Socket
Book a DemoInstallSign in
Socket

decimal-toformat

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decimal-toformat

A `toFormat` function for decimal.js

latest
Source
npmnpm
Version
3.0.1
Version published
Maintainers
1
Created
Source

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

Keywords

format

FAQs

Package last updated on 23 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts