Toggle menu

decimal.js

This library can be used to handle floating point numbers and is particularly useful when working with currency and payments.

This library is distributed under the MIT license. You can find the source and full documentation at https://www.npmjs.com/package/decimal.js/v/9.0.1.

Executed

Server-side.

Details

var decimal = require("decimal.js");

Decimal.js provides over forty methods that can be used to work with numbers. You will see it in the forms we deliver that work with payments to overcome the limitations around using floating points to store currency values.

As with all payment information, totals should be calculated server-side, not in the browser.

Multiplication Example

const Decimal = require("decimal.js");
let x = new Decimal(0.1);
let y = new Decimal("0.2");
let result = x.times(y);
return parseFloat(result); // returns 0.02

Last modified on 10 March 2020

Share this page

Facebook icon Twitter icon email icon

Print

print icon