Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

accurate

Ipxxiao116MIT1.5.8TypeScript support: included

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

accurate, accuracy, precision, arithmetic, calculation, floating-point, decimal, expression, add, addition, subtract, subtraction, mul, multiply, multiplication, division, divide, modulo, modulus, expr, 精度计算, 表达式精度计算, js 精度计算, js 小数计算, js 浮点数计算

readme

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

changelog

Release history

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

<summary>Guiding Principles</summary>
  • Changelogs are for humans, not machines.
  • There should be an entry for every single version.
  • The same types of changes should be grouped.
  • Versions and sections should be linkable.
  • The latest version comes first.
  • The release date of each versions is displayed.
  • Mention whether you follow Semantic Versioning.
<summary>Types of changes</summary>

Changelog entries are classified using the following labels (from keep-a-changelog):

  • Added for new features.
  • Changed for changes in existing functionality.
  • Deprecated for soon-to-be removed features.
  • Removed for now removed features.
  • Fixed for any bug fixes.
  • Security in case of vulnerabilities.

1.5.8 (2022-02-23)

  • Security update of dependabot alerts

1.5.7 (2021-04-07)

  • Security update y18n version

1.5.6 (2020-12-28)

  • Security update jest version

1.5.5 (2020-09-11)

  • Fixed expression evaluator

1.5.4 (2020-08-21)

  • Fixed expression evaluator

1.5.3 (2020-07-31)

  • Remove Codecov of dependencies

1.5.2 (2020-07-29)

  • Changed homepage link

1.5.1 (2020-07-24)

  • Changed core.ts to accurate-core dependencies

1.4.21 (2020-07-23)

  • Security bump lodash from 4.17.15 to 4.17.19. See (pull/2)
  • Security bump codecov from 3.7.0 to 3.7.1. See (pull/3)

1.4.20 (2020-07-10)

  • Remove Rollup of dependencies

1.4.19 (2020-07-10)

  • Add changelog file

1.4.18 (2020-07-8)

  • Add ESLint dependencies

1.4.17 (2020-07-08)

  • Add Coveralls automated test code coverage

1.4.16 (2020-07-07)

  • Add the method alias addition, subtraction, multiplication and modulus

1.4.14 (2020-07-07)

  • Change update dependencies
  • Change npm to yarn

1.4.13 (2020-07-07)

  • Change revert methods name

1.4.10 (2020-07-03)

  • Change optimize code performance

1.4.1 (2020-06-17)

  • Add support arrays, and matrices

1.3.1 (2020-06-16)

  • Add expression evaluator
  • Change methods name

1.2.5 (2020-06-09)

  • Security bump codecov from 3.6.1 to 3.6.5. See (pull/1)

1.2.1 (2019-12-02)

  • Add ESLint checks
  • Add JSDoc document generation
  • Add Jest unit tests
  • Add continuous integration service Travis CI
  • Add integration test coverage tool Codecov
  • Change the process of build, test and release

1.0.15 (2019-11-21)

  • Add documentation comments
  • Change js to ts

1.0.7 (2019-04-15)

  • Security update lodash version to 4.17.14

1.0.5 (2019-04-11)

  • Improvements methods

1.0.2 (2019-04-10)

  • First release