New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

deci-mal

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deci-mal

Decimal type for JavaScript

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
11
57.14%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

type

FAQs

Package last updated on 20 Feb 2014

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