Skip to content

parseNumber

ffredyk edited this page Jul 23, 2026 · 1 revision

parseNumber

Category

String

Arity

UnaryparseNumber <string>.

parseNumber <string>

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

parseNumber "123";             // 123
parseNumber "45.67";           // 45.67
parseNumber "-8.5";            // -8.5

Failure → nil

parseNumber "abc";             // nil
parseNumber "12abc";           // nil (partial not accepted)
parseNumber "";                // nil

Safe parsing with default

_val = parseNumber _input;
if (isNil "_val") then {
    _val = 0;                  // default fallback
};

Input validation

_isNumeric = !isNil parseNumber _input;
if (!_isNumeric) then {
    systemChat "Please enter a valid number";
};

Config value parsing

_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

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally