8000 GitHub - Edge00/number-calc: Calculate addition, subtraction, multiplication, and division precisely using JS
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Calculate addition, subtraction, multiplication, and division precisely using JS

License

Notifications You must be signed in to change notification settings

Edge00/number-calc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

number-calc npm version Build Status codecov

Calculate addition, subtraction, multiplication, and division precisely using JS

Why

0.1 + 0.2 = 0.30000000000000004
1.0 - 0.9 = 0.09999999999999998
1.1 * 1.1 = 1.2100000000000002
1.21 / 1.1 = 1.0999999999999999

Install

npm install --save number-calc

Methods

NC.add(number1, number2) // addition, number1 + number2
NC.subtract(number1, number2) // subtraction, number1 - number2
NC.multiply(number1, number2) // multiplication, number1 * number2
NC.divide(number1, number2) // division, number1 / number2
NC.prune(number, precision) // prune, precision defaults to 12

Usage

import NC from 'number-calc'

NC.add(0.1, 0.2) // 0.3, not 0.30000000000000004
NC.subtract(1.0, 0.9) // 0.1, not 0.09999999999999998
NC.multiply(1.1, 1.1) // 1.21, not 1.2100000000000002
NC.divide(1.21, 1.1) // 1.1, not 1.0999999999999999
NC.prune(0.30000000000000004) // 0.3

License

MIT

About

Calculate addition, subtraction, multiplication, and division precisely using JS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%
0