# parseNumber ## Category String ## Arity **Unary** — `parseNumber `. ``` parseNumber ``` ## Description Parses a string into a number (double). Returns the numeric value on success, or `nil` if the string cannot be parsed as a number. ## How It Works Calls `double.TryParse()` with invariant culture. Accepts integer and decimal formats (e.g., `"123"`, `"45.67"`, `"-8.5"`). Whitespace is trimmed. If parsing fails completely, returns `nil`. ## Usage ### Basic parsing ```sqf parseNumber "123"; // 123 parseNumber "45.67"; // 45.67 parseNumber "-8.5"; // -8.5 ``` ### Failure → nil ```sqf parseNumber "abc"; // nil parseNumber "12abc"; // nil (partial not accepted) parseNumber ""; // nil ``` ### Safe parsing with default ```sqf _val = parseNumber _input; if (isNil "_val") then { _val = 0; // default fallback }; ``` ### Input validation ```sqf _isNumeric = !isNil parseNumber _input; if (!_isNumeric) then { systemChat "Please enter a valid number"; }; ``` ### Config value parsing ```sqf _configValue = _config get "timeout"; // might be string "30" or number 30 if (typeName _configValue == "string") then { _configValue = parseNumber _configValue; }; ``` ## Thread Safety ReadOnly — pure computation. Safe from any scheduler. ## See Also - [str](str.md) — number to string - [format](format.md) — formatted output - [typeName](typeName.md) — check value type