Skip to main content

bignumber.js

tip
  • 如果考虑 bundle size 选择 big.js 否则选择 decimal.js
new BigNumber('ff.8', 16);
new Decimal('0xff.8');

// 处理小数的逻辑不一样
Bignumber.config({ DECIMAL_PLACES: 3, ROUNDING_MODE: 1 });
var x = new BigNumber('123.456789');
x.plus(1).toString(); // '124.456789'

Decimal.set({ precision: 7, rounding: 4 });
var y = new Decimal('123.456789');
y.plus(1).toString(); // '124.4568'
varstand for0.123-12345.67
ccoefficient1,2,31,2,3,4,5,6,7
eexponent-14
ssign1-1
configdefault
DECIMAL_PLACES20
ROUNDING_MODE4/ROUND_HALF_UP
EXPONENTIAL_AT[-7, 20]
RANGE[-1e+9, 1e+9]

Number

Number-
toString(base=10)
toFixed(digits=0)小数点后 n 位, 0 < digits < 20
toPrecision(precision?)总的 n 个有效数字, 无 precision = toString
toExponential(fractionDigits?)1.23e+5