decimal-toformat
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

toFormat

Adds a toFormat function to format decimal.js values.

Install

Node.js

$ npm install decimal-toformat

Use

Node.js

const Decimal = require("decimal.js");
const { toFormat } = require("decimal-toformat");

x = new Decimal(9876.54321);
toFormat(x, 2) ;                      // '9,876.54'

// Set some format properties
toFormat(x, 1, {
  decimalSeparator: ',',
  groupSeparator: ' ',
  groupSize: 2,
});                                  // '98 76,5'

Further examples:

let format = {
  decimalSeparator: '.',
  groupSeparator: ',',
  groupSize: 3,
  secondaryGroupSize: 0,
  fractionGroupSeparator: '',
  fractionGroupSize : 0
};

toFormat(x, format);                 // 123,456,789.987654321
toFormat(x, 2, 1, format);           // 123,456,789.98

toFormat(x, {
  decimalSeparator: ',',
  groupSeparator: '',
});                                  // 123456789,987654321

format = {
  decimalSeparator: '.',
  groupSeparator: ' ',
  groupSize: 3,
  fractionGroupSeparator: ' ',
  fractionGroupSize : 5
};

toFormat(x, format);                 // 123 456 789.98765 4321
toFormat(x, 4, format);              // 123 456 789.9877
toFormat(x, 2, 1, format);           // 123 456 789.98

Test

$ npm test

Licence

MIT

/decimal-toformat/

    Package Sidebar

    Install

    npm i decimal-toformat

    Weekly Downloads

    0

    Version

    3.0.1

    License

    MIT

    Unpacked Size

    7.45 kB

    Total Files

    5

    Last publish

    Collaborators

    • jangxx