_N
Format a floating-point number.
_N(num)
_N(num, precision)Examples
-
For example,
_N(3.1415, 2)keeps3.1415to two decimal places, removes the remaining digits, and the function returns3.14.javascriptfunction main(){ var i = 3.1415 Log(i) var ii = _N(i, 2) Log(ii) }pythondef main(): i = 3.1415 Log(i) ii = _N(i, 2) Log(ii)rustfn main() { let i = 3.1415; Log!(i); let ii = _N(i, 2); Log!(ii); } -
If you need to set the N digits to the left of the decimal point all to 0, you can write it like this.
javascriptfunction main(){ var i = 1300 Log(i) var ii = _N(i, -3) // Check the log and you will see it is 1000 Log(ii) }pythondef main(): i = 1300 Log(i) ii = _N(i, -3) Log(ii)rustfn main() { let i = 1300; Log!(i); let ii = _N(i, -3); // Check the log and you will see it is 1000 Log!(ii); }
Returns
| Type | Description |
number | The floating-point number formatted according to the precision setting. |
Arguments
| Name | Type | Required | Description |
num | number | Yes | The floating-point number to be formatted. |
precision | number | No | Used to set the formatting precision. The parameter |
See Also
Remarks
The parameter precision can be a positive integer or a negative integer.