si-number

0.1.0 • Public • Published

si-number stable

Formats numbers using SI prefixes.

Options

You can pass a configuration object as second parameter with the following keys:

  • decimal: Symbol to use for decimal point (default: .).
  • precision: Number of decimal digits to show (default: 2).
  • separator: Separator between digits and prefix (default: empty string).
  • thousands: It true, only uses prefixes that are multiples of 1000.

Usage

npm install si-number

const siNumber = require('si-number');
 
// 2.5 centimeters, without thousands scale.
console.log(
    '%sm',
    siNumber(
        0.025,
        {
            precision : 1
        }
    )
); // 2.5cm
// 2.5 centimeters, using thousands scale.
console.log(
    '%sm',
    siNumber(
        0.025,
        {
            decimal   : ',',
            precision : 1,
            thousands : true
        }
    )
); // 25,0mm

/si-number/

    Package Sidebar

    Install

    npm i si-number

    Weekly Downloads

    30

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • joaquinfq