nFormat() Netscript Function

nFormat(n, format)
Arguments:
  • n (number) – Number to format
  • format (string) – Formatter

Converts a number into a string with the specified formatter. This uses the numeraljs library, so the formatters must be compatible with that.

This is the same function that the game itself uses to display numbers.

Examples:

nFormat(1.23e9, "$0.000a"); // Returns "$1.230b"
nFormat(12345.678, "0,0");  // Returns "12,346"
nFormat(0.84, "0.0%");      // Returns "84.0%