toFixed: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) mNo edit summary |
Killzone Kid (talk | contribs) mNo edit summary |
||
Line 8: | Line 8: | ||
| 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 [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed toFixed()]<br><br> | | 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 [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed toFixed()]<br><br> | ||
'''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 [https://en.wikipedia.org/wiki/Significant_figures significant figures], whereas with this command it is possible to preserve some extra precision. ( | '''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 [https://en.wikipedia.org/wiki/Significant_figures significant figures], whereas with this command it is possible to preserve some extra precision. | ||
<code>[[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</code>|= Description | |||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
Revision as of 20:24, 2 September 2016
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
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
[[Category:Introduced with arma3dev version 1.65]][[ Category: arma3dev: New Scripting Commands | TOFIXED]][[ Category: arma3dev: Scripting Commands | TOFIXED]]