toFixed: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - "\| *((\[\[[a-zA-Z0-9_ |()]+\]\],? ?)+) * \}\}" to "|seealso= $1 }}") |
m (Text replacement - "v1\.71\.[0-9]{6}" to "v1.72") |
||
Line 17: | Line 17: | ||
[[pi]] [[toFixed]] 7; //"3.1415927" - forced to 8 significant figures</code> | [[pi]] [[toFixed]] 7; //"3.1415927" - forced to 8 significant figures</code> | ||
Since Arma 3 v1. | Since Arma 3 v1.72 an alternative syntax is added, which takes no number and returns [[Nothing]]. Instead it acts as keyword and switches engine [[Number]] to [[String]] global conversion into desired format, from the moment it is applied until the end of script. To reset output back to default at any time, use <tt>toFixed -1</tt>. For example: | ||
<code>[[systemChat]] [[str]] [[position]] [[player]]; | <code>[[systemChat]] [[str]] [[position]] [[player]]; | ||
[[call]] | [[call]] |
Revision as of 10:22, 3 April 2021
Description
- Description:
- Description needed
- Groups:
- MathStrings
Syntax
- Syntax:
- Syntax needed
- Parameters:
- number: Number - number to convert
- decimals: Number - number of decimals to display (range 0-20)
- Return Value:
- Return value needed
Alternative Syntax
- Syntax:
- toFixed decimals Template:Since
- Parameters:
- decimals: Number - number of decimals to display (range 0-20). -1 to reset to default number of decimals
- Return Value:
- Nothing
Examples
- Example 1:
123 toFixed 2; // "123.00"
- Example 2:
2.34 toFixed 1; // "2.3" 2.35 toFixed 1; // "2.4"
- Example 3:
- Convert position to string preserving position precision:
fn_posToString = { format [ "[%1,%2,%3]", _this select 0 toFixed 8, _this select 1 toFixed 8, _this select 2 toFixed 8 ] }; str getPos player; // "[3231.05,171.802,0.00143862]" getPos player call fn_posToString; // "[3231.04882813,171.80192566,0.00143862]"
- Example 4:
- Same as Example 3 only using new alternative syntax:
str getPos player; // "[3231.05,171.802,0.00143862]" toFixed 8; str getPos player; // "[3231.04882813,171.80192566,0.00143862]"
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
- Posted on September 2, 2016 - 21:56 (UTC)
- R3vo
-
parseNumber (3.56346 toFixed 4); //0.0026 ms (10000 cycles)
[3.5634,4] call BIS_fnc_cutDecimals; //0.0111 ms (10000 cycles)