zxpnet网站 zxpnet网站
首页
前端
后端服务器
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

zxpnet

一个爱学习的java开发攻城狮
首页
前端
后端服务器
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 大前端课程视频归档
  • html

  • js

    • Promise从入门到自定义
    • js小数计算BigNumber
      • math.js
      • BigNumber.js
      • decimal.js
      • big.js
    • 二维码qrcode插件
    • 常用js插件
    • 富文本编辑器
    • 数据可视化Echarts
  • 前端框架

  • 自动化构建

  • typescript

  • es6

  • bootstrap

  • layer

  • vue

  • vue3

  • vuepress

  • hexo博客

  • 文档

  • biz业务

  • frontend
  • js
shollin
2021-09-23
目录

js小数计算BigNumber

  • math.js
  • BigNumber.js
  • decimal.js
  • big.js

# math.js

<script src="https://cdn.bootcdn.net/ajax/libs/mathjs/9.4.4/math.min.js"></script>

// functions and constants
math.round(math.e, 3)                // 2.718
math.atan2(3, -3) / math.pi          // 0.75
math.log(10000, 10)                  // 4
math.sqrt(-4)                        // 2i
math.pow([[-1, 2], [3, 1]], 2)       // [[7, 0], [0, 7]]

// expressions
math.evaluate('12 / (2.3 + 0.7)')    // 4
math.evaluate('12.7 cm to inch')     // 5 inch
math.evaluate('sin(45 deg) ^ 2')     // 0.5
math.evaluate('9 / 3 + 2i')          // 3 + 2i
math.evaluate('det([-1, 2; 3, 1])')  // -7

// chained operations
math.chain(3)
    .add(4) // 加
    .multiply(2) // 乘
    .done() // 14
    
function funAdd(a,b){
         math.config({
            number: 'BigNumber'
        });
        return math.parser().eval(a + "+" + b);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

参考文章 :math.js:灵活强大的JavaScript数学库 - 简书 (jianshu.com) (opens new window)

# BigNumber.js

<script src="https://cdn.bootcdn.net/ajax/libs/bignumber.js/9.0.1/bignumber.min.js"></script>

1
2

参考: JS中调用bignumber处理高精度小数运算 - 先锋之客 - 博客园 (cnblogs.com) (opens new window)

bignumber.js API (mikemcl.github.io) (opens new window)

# decimal.js

# big.js

<script src="https://cdn.bootcdn.net/ajax/libs/big.js/6.1.1/big.min.js"></script>

Big(record.count).times(record.price).plus(result).minus(100); // 乘、加、减、除div
1
2
3

big.js API (mikemcl.github.io) (opens new window)

Promise从入门到自定义
二维码qrcode插件

← Promise从入门到自定义 二维码qrcode插件→

最近更新
01
国际象棋
09-15
02
成语
09-15
03
自然拼读
09-15
更多文章>
Theme by Vdoing | Copyright © 2019-2023 zxpnet | 粤ICP备14079330号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式