一个JavaScript的任意精度的十进制类型:decimal.js
jopen
10年前
一个JavaScript的任意精度的十进制类型:decimal.js。
特性
- 更快,更小,或许更容易使用比Java版本的BigDecimal
- 简单的API,但功能齐全
- Replicates the
toExponential
,toFixed
,toPrecision
andtoString
methods of JavaScript's Number type - Includes a
toFraction
and correctly-roundedexp
,ln
,log
andsqrt
functions - Supports non-integer powers
- Works with numbers with or without fraction digits in bases from 2 to 64 inclusive
- No dependencies
- Wide platform compatibility: uses JavaScript 1.5 (ECMAScript 3) features only
- Comprehensive documentation and test set
- 8 KB minified and gzipped
x = new Decimal(123.4567) y = new Decimal('123456.7e-3') z = new Decimal(x) x.equals(y) && y.equals(z) && x.equals(z) // true