toFixed: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 41: Line 41:
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on September 2, 2016 - 21:56 (UTC)</dd>
<dt class="note">[[User:Revo|Revo]]</dt>
<dd class="note">
[[parseNumber]] (3.56346 '''toFixed''' 4); //0.0026 ms (10000 cycles)<br><br>
[3.5634,4] [[call]] [[BIS_fnc_cutDecimals]]; //0.0111 ms (10000 cycles)
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Revision as of 23:56, 2 September 2016

-wrong parameter ("arma3dev") defined!-[[:Category:Introduced with arma3dev version 1.65|1.65]]
Hover & click on the images for description

Description

Description:
Converts a number into a string, keeping a specified number of decimals. If the desired number of decimals are higher than the actual number, nulls are added to create the desired decimal length. This command is almost identical in behaviour to JavaScript toFixed()

NOTE: Converted number is never presented in scientific notation unlike with other number to string commands. Also Arma's default string conversion limits numbers to 6 significant figures, whereas with this command it is possible to preserve some extra precision. str (pi/100000); //"3.14159e-005" - scientific notation (pi/100000) toFixed 10; //"0.0000314159" - no scientific notation str pi; //"3.14159" - 6 significant figures (default) pi toFixed 6; //"3.141593" - forced to 7 significant figures pi toFixed 7; //"3.1415927" - forced to 8 significant figures
Groups:
Uncategorised

Syntax

Syntax:
number toFixed decimals
Parameters:
number: Number - number to convert
decimals: Number - number of decimals to display (range 0-20)
Return Value:
String

Examples

Example 1:
123 toFixed 2; //"123.00"
Example 2:
2.34 toFixed 1; //"2.3" 2.35 toFixed 1; //"2.4"

Additional Information

See also:
toStringtoArraytoLowertoUpper

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

[[Category:Introduced with arma3dev version 1.65]][[ Category: arma3dev: New Scripting Commands | TOFIXED]][[ Category: arma3dev: Scripting Commands | TOFIXED]]

Notes

Bottom Section

Posted on September 2, 2016 - 21:56 (UTC)
Revo
parseNumber (3.56346 toFixed 4); //0.0026 ms (10000 cycles)

[3.5634,4] call BIS_fnc_cutDecimals; //0.0111 ms (10000 cycles)