Type/to search
Built-in Functions
Global
Version
IsVirtual
GetOS
GetPid
GetMeta
Sleep
Unix
UnixNano
_D
GetCommand
GetLastError
SetErrorFilter
_N
_C
_Cross
JSON.parse
JSON.stringify
Encode
MD5
UUID
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Format a floating-point number.

_N(num)
_N(num, precision)

Examples

  • For example, _N(3.1415, 2) keeps 3.1415 to two decimal places, removes the remaining digits, and the function returns 3.14.

    javascript
    function main(){ var i = 3.1415 Log(i) var ii = _N(i, 2) Log(ii) }
    python
    def main(): i = 3.1415 Log(i) ii = _N(i, 2) Log(ii)
    rust
    fn 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.

    javascript
    function main(){ var i = 1300 Log(i) var ii = _N(i, -3) // Check the log and you will see it is 1000 Log(ii) }
    python
    def main(): i = 1300 Log(i) ii = _N(i, -3) Log(ii)
    rust
    fn main() { let i = 1300; Log!(i); let ii = _N(i, -3); // Check the log and you will see it is 1000 Log!(ii); }

Returns

TypeDescription

number

The floating-point number formatted according to the precision setting.

Arguments

NameTypeRequiredDescription

num

number

Yes

The floating-point number to be formatted.

precision

number

No

Used to set the formatting precision. The parameter precision is an integer, with a default value of 4.

See Also

Remarks

The parameter precision can be a positive integer or a negative integer.