parseNumber: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(note)
(description)
Line 7: Line 7:
____________________________________________________________________________________________
____________________________________________________________________________________________


| Parse string containing real number. |= Description
| 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.  |= Description
____________________________________________________________________________________________
____________________________________________________________________________________________


Line 17: Line 17:
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= <code>_number = [[parseNumber]] "0.125";</code> |= Example 1
|x1= _number <nowiki>=</nowiki> '''parseNumber''' "0.125" |= Example 1
____________________________________________________________________________________________
____________________________________________________________________________________________


| [[BIS_fnc_parseNumber]] |= See also
| |= See also


}}
}}
Line 27: Line 27:
<dl class="command_description">
<dl class="command_description">
<!-- Note Section BEGIN -->
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on Aug 28, 2014
* If the text does not represent a number ("abc" for example), parseNumber will return 0 (zero). It is therefore not possible to use parseNumber to determine if the string contains a valid number or not.
<dt class="note">[[User:ffur2007slx2_5|ffur2007slx2_5]]
<strong>I beg to differ.</strong><br />
<dd class="note"> (A3 1.26)It only detects the first occurrence of a number in the string, return 0 by default.
_stringNotContainingValidNumber = "abc";
<code>[[parseNumber]] "2s4f"; // 2
if(parseNumber _stringNotContainingValidNumber == 0 && _stringNotContainingValidNumber != "0") then
[[parseNumber]] "s2f4"; // 0</code>
{
parse config or code, currently [[BIS_fnc_parseNumber]], occurrence is only limited with number, return -1 by default.
    comment "INVALID NUMBER";
<code>{s3s4f} [[call]] [[BIS_fnc_parseNumber]]; // -1</code>
}
else
{
    comment "VALID NUMBER";
};
[[User:MulleDK13|MulleDK13]] 09:26, 11 July 2010 (CEST)
<!-- Note Section END -->
<!-- Note Section END -->
</dl>
</dl>
Line 42: Line 47:
[[Category:Command_Group:_Variables|{{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 VBS2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]

Revision as of 22:47, 2 October 2014

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

Description

Description:
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:
Number = parseNumber string
Parameters:
string: String
Return Value:
Number

Examples

Example 1:
_number = parseNumber "0.125"

Additional Information

See also:
See also needed

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

  • If the text does not represent a number ("abc" for example), parseNumber will return 0 (zero). It is therefore not possible to use parseNumber to determine if the string contains a valid number or not.
I beg to differ.
_stringNotContainingValidNumber = "abc"; if(parseNumber _stringNotContainingValidNumber == 0 && _stringNotContainingValidNumber != "0") then { comment "INVALID NUMBER"; } else { comment "VALID NUMBER"; }; MulleDK13 09:26, 11 July 2010 (CEST)

Bottom Section