parseNumber: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "|SYNTAX= |p21=" to "|SYNTAX2= |p21=")
Line 7: Line 7:
____________________________________________________________________________________________
____________________________________________________________________________________________


| 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.
| 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>
<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 [https://community.bistudio.com/wiki/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.
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 [https://community.bistudio.com/wiki/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>
<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. |DESCRIPTION=
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. |DESCRIPTION=
____________________________________________________________________________________________
____________________________________________________________________________________________


| '''parseNumber''' string |SYNTAX=
| [[parseNumber]] string |SYNTAX=


|p1= string: [[String]] |PARAMETER1=
|p1= string: [[String]] |PARAMETER1=
Line 18: Line 18:
| [[Number]] |RETURNVALUE=
| [[Number]] |RETURNVALUE=


| s2= '''parseNumber''' boolean &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;''(Since Arma 3 v1.49.131731)''|SYNTAX2=
|s2= [[parseNumber]] boolean {{since|arma3|1.49.131731|y}} |SYNTAX2=


|p21= boolean: [[Boolean]] |PARAMETER1=
|p21= boolean: [[Boolean]] |PARAMETER21=


| r2= [[Number]] - 0 if [[false]], 1 if [[true]]|RETURNVALUE=
|r2= [[Number]] - 0 if [[false]], 1 if [[true]] |RETURNVALUE2=
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= <code>_number = [[parseNumber]] "0.125"; //0.125</code> |EXAMPLE1=
|x1= <code>_number = [[parseNumber]] "0.125"; {{cc|0.125}}</code> |EXAMPLE1=


|x2= <code>_number = [[parseNumber]] "2 abc"; //2</code> |EXAMPLE2=
|x2= <code>_number = [[parseNumber]] "2 abc"; {{cc|2}}</code> |EXAMPLE2=


|x3= <code>_number = [[parseNumber]] [[true]]; //1</code> |EXAMPLE3=
|x3= <code>_number = [[parseNumber]] [[true]]; {{cc|1}}</code> |EXAMPLE3=
____________________________________________________________________________________________
____________________________________________________________________________________________


| [[BIS_fnc_parseNumber]] |SEEALSO=
| [[BIS_fnc_parseNumber]] |SEEALSO=
}}
}}


Line 39: Line 38:
<dl class="command_description">
<dl class="command_description">
<!-- Note Section BEGIN -->
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on Aug 28, 2014
<dd class="notedate">Posted on Aug 28, 2014
<dt class="note">[[User:ffur2007slx2_5|ffur2007slx2_5]]
<dt class="note">[[User:ffur2007slx2_5|ffur2007slx2_5]]
Line 46: Line 46:
parse config or code, currently [[BIS_fnc_parseNumber]], occurrence is only limited with number, return -1 by default.
parse config or code, currently [[BIS_fnc_parseNumber]], occurrence is only limited with number, return -1 by default.
<code>{s3s4f} [[call]] [[BIS_fnc_parseNumber]]; // -1</code>
<code>{s3s4f} [[call]] [[BIS_fnc_parseNumber]]; // -1</code>
<!-- Note Section END -->
<!-- Note Section END -->
</dl>
</dl>


<h3 style="display:none">Bottom Section</h3>
<h3 style="display:none">Bottom Section</h3>
[[Category:Scripting Commands|PARSENUMBER]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA|PARSENUMBER]]
[[Category:Scripting Commands ArmA|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
 
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]
<!-- CONTINUE Notes -->
<!-- DISCONTINUE Notes -->

Revision as of 23:27, 21 December 2019

-wrong parameter ("Arma") defined!-1.00
Hover & click on the images for description

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:
Uncategorised

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 "2 abc"; // 2
Example 3:
_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

Bottom Section