[go: up one dir, main page]

accurate
TypeScript icon, indicating that this package has built-in type declarations

1.5.8 • Public • Published

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, multidimensional array 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 multidimensional array.

  • 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(表达式)

const a = 0.3
const b = 0.1

>
0.3 - 0.1
accurate.expr(`${a}-${b}`)

<-
0.19999999999999998
0.2
>
((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

Package Sidebar

Install

npm i accurate

Weekly Downloads

72

Version

1.5.8

License

MIT

Unpacked Size

83.7 kB

Total Files

22

Last publish

Collaborators

  • jsonchou
  • ipxxiao