Skip to main content


Converts a string of numeric characters to a float value


Device + Agent


Float — the value of the numeric string


This method returns the float value represented by the target string, which must contain only numeric characters, and the minus and plus symbols to indicate negative and positive values, respectively. The presence of other characters will cause Squirrel to post a ‘cannot convert the string’ error.

To trap cases where the string is not numeric, use Squirrel’s try... catch structure:

local aString = "Zap!";
local value = -1.0;

try {
    local = aString.tofloat();
catch (err) {
    server.error("Integer conversion attempted on non-numeric string; defaulting to 0.0");
    local = 0.0;

// Logs '0.0'

Example Code