parseNumber: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
(Added more details about parsing hex numbers) |
||
(91 intermediate revisions by 19 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{RV|type=command | ||
| | |game1= arma1 | ||
|version1= 1.00 | |||
|1.00 | |game2= arma2 | ||
|version2= 1.00 | |||
| | |game3= arma2oa | ||
|version3= 1.50 | |||
| | |game4= tkoh | ||
|version4= 1.00 | |||
| | |game5= arma3 | ||
|version5= 0.50 | |||
| | |gr1= Strings | ||
| | |descr= Parses the string, interpreting its content as a floating point number. | ||
{{Feature|important|This command does '''not''' work with strings representing hexadecimal numbers (e.g {{hl|"0xCF"}}). | |||
<sqf> | |||
parseNumber "512 + 0x2F"; // 512, WRONG! | |||
"512 + 0x2F" call BIS_fnc_parseNumber // 559, CORRECT! | |||
</sqf>}} | |||
{{Feature|informative|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.}} | |||
}} | |s1= [[parseNumber]] value | ||
|p1= value: [[String]] or {{GVI|arma3|1.50|size= 0.75}} [[Boolean]] | |||
|r1= [[Number]] - the parsed number, {{hl|0}} if no valid number was found; in the case of a passed [[Boolean]], 0 if [[false]], 1 if [[true]] | |||
< | |x1= <sqf> | ||
_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 | |||
</sqf> | |||
< | |x2= since {{arma3}} v1.50: | ||
</ | <sqf> | ||
_result = parseNumber false; // 0 | |||
_result = parseNumber true; // 1 | |||
_zeroOneStatus = parseNumber alive player; // 0 if the player is dead, 1 if alive | |||
</sqf> | |||
|seealso= [[BIS_fnc_parseNumber]] {{Link|http://www.cplusplus.com/reference/cstdlib/atof/|atof (C++)}} [[Floating Point Number#Floating Point Literals|Floating point literals]] | |||
[[ | }} | ||
[[ |
Latest revision as of 11:39, 10 May 2024
Description
- Description:
- Parses the string, interpreting its content as a floating point number.
- Groups:
- Strings
Syntax
- Syntax:
- parseNumber value
- Parameters:
- value: String or 1.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:
- Example 2:
- since Arma 3 v1.50:
Additional Information
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
Categories:
- Scripting Commands
- Introduced with Armed Assault version 1.00
- ArmA: Armed Assault: New Scripting Commands
- ArmA: Armed Assault: Scripting Commands
- Arma 2: Scripting Commands
- Arma 2: Operation Arrowhead: Scripting Commands
- Take On Helicopters: Scripting Commands
- Arma 3: Scripting Commands
- Command Group: Strings