parseNumber: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\[ *(https?:\/\/[^ = ]+) +([^= ]+) *\]" to "{{Link|$1|$2}}")
m (Some wiki formatting)
Line 31: Line 31:
_number = parseNumber "0.125"; // 0.125
_number = parseNumber "0.125"; // 0.125
_number = parseNumber "0050"; // 50
_number = parseNumber "0050"; // 50
_number = parseNumber "   42 yes"; // 42
_number = parseNumber " 42 yes"; // 42
_number = parseNumber "3 or 4"; // 3
_number = parseNumber "3 or 4"; // 3
_number = parseNumber "either 3 or 4"; // 0
_number = parseNumber "either 3 or 4"; // 0
Line 39: Line 39:
|x2= since {{arma3}} v1.50:
|x2= since {{arma3}} v1.50:
<sqf>
<sqf>
private _result = parseNumber false; // 0
_result = parseNumber false; // 0
private _result = parseNumber true; // 1
_result = parseNumber true; // 1
private _zeroOneStatus = parseNumber alive player; // 0 if the player is dead, 1 if alive
_zeroOneStatus = parseNumber alive player; // 0 if the player is dead, 1 if alive
</sqf>
</sqf>


|seealso= [[BIS_fnc_parseNumber]] {{Link|http://www.cplusplus.com/reference/cstdlib/atof/|atof (C++)}} [[Floating Point Number#Floating Point Literals|Floating point literals]]
|seealso= [[BIS_fnc_parseNumber]] {{Link|http://www.cplusplus.com/reference/cstdlib/atof/|atof (C++)}} [[Floating Point Number#Floating Point Literals|Floating point literals]]
}}
}}

Revision as of 13:22, 12 March 2024

Hover & click on the images for description

Description

Description:
Parses the string, interpreting its content as a floating point number.
This command does not work with strings representing hexadecimal numbers (e.g "0xCF").
Starting whitespaces are discarded, then as many valid characters are used to be interpreted as a number until an invalid character is found then the rest of the string is ignored.
Groups:
Strings

Syntax

Syntax:
parseNumber value
Parameters:
value: String or Arma 3 logo black.png1.50 Boolean
Return Value:
Number - the parsed number, 0 if no valid number was found; in the case of a passed Boolean, 0 if false, 1 if true

Examples

Example 1:
_number = parseNumber "0.125"; // 0.125 _number = parseNumber "0050"; // 50 _number = parseNumber " 42 yes"; // 42 _number = parseNumber "3 or 4"; // 3 _number = parseNumber "either 3 or 4"; // 0 _number = parseNumber "0xCF"; // 0
Example 2:
since Arma 3 v1.50:
_result = parseNumber false; // 0 _result = parseNumber true; // 1 _zeroOneStatus = parseNumber alive player; // 0 if the player is dead, 1 if alive

Additional Information

See also:
BIS_fnc_parseNumber atof (C++) Floating point literals

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note