parseNumber: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - "_{10,} " to "") |
Lou Montana (talk | contribs) m (Text replacement - " *\| *([Cc]omments|COMMENTS|Game|[Gg]ame [Nn]ame|Game [Vv]ersion|Game Version \(number surrounded by NO SPACES\)|Multiplayer Arguments( \("local" or "global"\))?|Effects|Multiplayer Effects( \("local" or "global"\))?|Multiplayer Exe...) |
||
Line 1: | Line 1: | ||
{{Command | {{Command | ||
| arma1 | | arma1 | ||
|1.00 | |1.00 | ||
|gr1= Strings | |gr1= Strings | ||
| An SQF equivalent of C++ [http://www.cplusplus.com/reference/cstdlib/atof/ atof] function. Parses the string, interpreting its content as a floating point number.<br><br> | | An SQF equivalent of C++ [http://www.cplusplus.com/reference/cstdlib/atof/ atof] function. Parses the string, interpreting its content as a floating point number.<br><br> | ||
The command first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of [[Floating_Point_Number#Floating_Point_Literals|floating point literals]], and interprets them as a numerical value. The rest of the string after the last valid character is ignored and has no effect on the behavior of this command.<br><br> | The command first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of [[Floating_Point_Number#Floating_Point_Literals|floating point literals]], and interprets them as a numerical value. The rest of the string after the last valid character is ignored and has no effect on the behavior of this command.<br><br> | ||
If the first sequence of non-whitespace characters in string does not form a valid floating-point number, or if no such sequence exists because either string is empty or contains only whitespace characters, no conversion is performed and the command returns 0. | If the first sequence of non-whitespace characters in string does not form a valid floating-point number, or if no such sequence exists because either string is empty or contains only whitespace characters, no conversion is performed and the command returns 0. | ||
| [[parseNumber]] string | | [[parseNumber]] string | ||
|p1= string: [[String]] | |p1= string: [[String]] | ||
| [[Number]] | | [[Number]] | ||
|s2= [[parseNumber]] boolean {{Since|arma3|1.49.131731|y}} | |s2= [[parseNumber]] boolean {{Since|arma3|1.49.131731|y}} | ||
|p21= boolean: [[Boolean]] |PARAMETER21= | |p21= boolean: [[Boolean]] |PARAMETER21= | ||
|r2= [[Number]] - 0 if [[false]], 1 if [[true]] | |r2= [[Number]] - 0 if [[false]], 1 if [[true]] | ||
|x1= <code>_number = [[parseNumber]] "0.125"; {{cc|0.125}}</code> | |x1= <code>_number = [[parseNumber]] "0.125"; {{cc|0.125}}</code> | ||
|x2= <code>_number = [[parseNumber]] "0050"; {{cc|50}}</code> | |x2= <code>_number = [[parseNumber]] "0050"; {{cc|50}}</code> | ||
|x3= <code>_number = [[parseNumber]] "2 abc"; {{cc|2}}</code> | |x3= <code>_number = [[parseNumber]] "2 abc"; {{cc|2}}</code> | ||
|x4= <code>_number = [[parseNumber]] [[true]]; {{cc|1}}</code> | |x4= <code>_number = [[parseNumber]] [[true]]; {{cc|1}}</code> | ||
| [[BIS_fnc_parseNumber]] | | [[BIS_fnc_parseNumber]] | ||
}} | }} | ||
Revision as of 01:25, 18 January 2021
Description
- Description:
- An SQF equivalent of C++ atof function. Parses the string, interpreting its content as a floating point number.
The command first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of floating point literals, and interprets them as a numerical value. The rest of the string after the last valid character is ignored and has no effect on the behavior of this command.
If the first sequence of non-whitespace characters in string does not form a valid floating-point number, or if no such sequence exists because either string is empty or contains only whitespace characters, no conversion is performed and the command returns 0. - Groups:
- Strings
Syntax
- Syntax:
- parseNumber string
- Parameters:
- string: String
- Return Value:
- Number
Alternative Syntax
- Syntax:
- parseNumber boolean Template:Since
- Parameters:
- boolean: Boolean
- Return Value:
- Number - 0 if false, 1 if true
Examples
- Example 1:
_number = parseNumber "0.125"; // 0.125
- Example 2:
_number = parseNumber "0050"; // 50
- Example 3:
_number = parseNumber "2 abc"; // 2
- Example 4:
_number = parseNumber true; // 1
Additional Information
- See also:
- BIS_fnc_parseNumber
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
Notes
- Posted on Aug 28, 2014
- ffur2007slx2_5
- (A3 1.26)It only detects the first occurrence of a number in the string, return 0 by default.
parseNumber "2s4f"; // 2 parseNumber "s2f4"; // 0
parse config or code, currently BIS_fnc_parseNumber, occurrence is only limited with number, return -1 by default.{s3s4f} call BIS_fnc_parseNumber; // -1