Awesome Open Source
Awesome Open Source

Accurate · NPM version NPM downloads Build Status Coverage Status code style: prettier

  • Accurate is an precision calculation for JavaScript and Nodejs. supports numbers, decimals, strings, arrays, matrices and expression.
  • 解决 JavaScript 与 Node.js 精度计算(浮点数计算精度)问题。支持数字、小数、字符串、数组、矩阵和表达式。

Browsers support

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
iOS Safari
iOS Safari
Opera
Opera
IE8+ Edge+ last 10 versions last 10 versions last 2 versions last 2 versions last 2 versions

Install

npm i accurate -S
or
yarn add accurate

Features

  • Supports numbers, decimals, strings, arrays and matrices.

  • Contains arithmetic expression parser.

  • Runs on any JavaScript engine.

  • Is easily extensible.

  • Open source.

  • 支持数字、小数、字符串、数组和矩阵。

  • 包含算术表达式解析器。

  • 运行在任何 JavaScript 引擎。

  • 易于扩展。

  • 开源的。

Usage

import accurate, {
  add, addition, subtract, subtraction, multiply, mul, multiplication, division, divide, modulo, modulus, expr
} from 'accurate'
or
const accurate, {
  add, addition, subtract, subtraction, multiply, mul, multiplication, division, divide, modulo, modulus, expr
} = require('accurate')

. add(加法)

>
1.1 + 0.3 + 0.1
accurate.add(1.1, 0.3, 0.1)
addition(1.1, 0.3, 0.1)

<-
1.5000000000000002
1.5
1.5

. subtract(减法)

>
1.1 - 0.2 - 0.1
accurate.subtract([1.1, 0.2, 0.1])
subtraction([1.1, 0.2, 0.1])

<-
0.8000000000000002
0.8
0.8

. multiply(乘法)

>
1.1 * 0.1 * 0.2
accurate.multiply([1.1, [0.1, 0.2]])
accurate.mul([1.1, [0.1, 0.2]])
multiplication([1.1, [0.1, 0.2]])

<-
0.022000000000000006
0.022
0.022
0.022

. division(除法)

>
1.1 / 10 / 2
accurate.division([1.1, 10], 2)
accurate.divide([1.1, 10], 2)

<-
0.05500000000000001
0.055
0.055

. modulo(取模)

>
1.1 % 1
accurate.modulo(1.1, 1)
accurate.modulus(1.1, 1)

<-
0.10000000000000009
0.1
0.1

. expr(表达式)

>
((1.1+0.3)*4+2*3)/(1.1%0.3-1*0.1)-1*5
accurate.expr('((1.1+0.3)*4+2*3)/(1.1%0.3-1*0.1)-1*5')
accurate.expr('((1.1 + 0.3) * 4 + 2 * 3) / (1.1 % 0.3 - 1 * 0.1) - 1 * 5')

<-
110.99999999999987
111
111

More


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,555,917
Typescript (254,029
Nodejs (54,817
Floating Point (286
Expression (279
Arithmetic (205
Matrices (155
Accuracy (134
Precision (133
Related Projects