JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q38913F

Decimal type for JavaScript

Package Exports

  • deci-mal

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (deci-mal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Deci-mal

Simple Decimal type for Javascript.

Simple Decimal type which allows for:

  • conversion from numbers;
  • conversion from strings;
  • specification of precision;
  • changing of precision;
  • addition of Decimals;
  • subtraction of Decimals;
  • multiplication of Decimals;
  • division of Decimals.

When doing add, sub, mult, div-operators with two Decimals, the result will have the precision of the source Decimal with the highest precision.

Deci-mal uses an integer for internal storage.

Deci-mal is released under the Simplified BSD License.

Example usage

var decimal = require('./');
var Decimal = decimal.decimal;

// conversion from numbers
var a = decimal.fromNumber(20, 2); // 20.00
var b = decimal.fromNumber(40.1, 4); // 40.1000

// conversion from strings
var c = decimal.fromString('60.60001', 2); // 60.60

// specification of precision
var d = new Decimal(1); // 0.0

// changing of precision
b.newPrecision(2).toString(); // 40.10

// addition
a.add(b).toString(); // 60.1000

// subtraction
a.sub(b).toString(); // -20.1000

// multiplication
a.mult(b).toString(); // 802.0000

// division
a.div(b).toString(); // 0.4988

Unit testing

Unit tests are built using Mocha.