Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

calculate-asmd

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calculate-asmd

加减乘除四则运算(calculate/arithmetic)

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

calculate-asmd

javascript 精确四则运算

生产原因

  1. 浮点数值的最高进度是 17 位小数,但在进行运算的时候其精确度却远远不如整数;整数在进行运算的时候都会转成 10 进制。
  2. Java 和 JavaScript 中计算小数运算时,都会先将十进制的小数换算到对应的二进制,一部分小数并不能完整的换算为二进制,这里就出现了第一次的误差。
  3. 待小数都换算为二进制后,再进行二进制间的运算,得到二进制结果。然后再将二进制结果换算为十进制,这里通常会出现第二次的误差。

使用

安装

yarn add calculate-asmd --dev

or

npm install calculate-asmd --save-dev

Demo
import { add, sub, mul, div } from 'calculate-asmd'

/** 加法 */
  const addNum = add(9.9, 0.2);
  console.log("add: ", addNum);

/** 减法 */
  const subNum = sub(9.9, 0.2);
  console.log("sub: ", subNum);

/** 乘法 */
  const mulNum = mul(9.9, 0.2);
  console.log("mul: ", mulNum);

/** 除法 */
  const divNum = div(9.9, 0.2);
  console.log("div: ", divNum);

参考

精确四则运算

js 小数运算出现多位小数如何解决

Keywords

FAQs

Package last updated on 02 Mar 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc