The front end uses bigDecimal.js for high-precision calculations
Reasons why the front end uses bigDecimal.js calculations:
In computer binary, the representation of floating point is caused by inaccuracy. Floating-point data types float and double are prone to loss of precision during operations, resulting in inaccurate data. BigDecimal can implement high-precision floating-point operations.
the case
For example, if you print on the browser console: 19.9 100 , there will be a loss of precision.
Use bigDecimal
addition add
a: string first addend
b: sting second addend
c: num precision
bigDecimal.add(a,b,c)
subtraction
a: string minuend
b: sting subtrahend
c: num precision
bigDecimal.subtract(a,b,c)
multiplication multiply
a: string first factor
b: sting second factor
c: num precision
bigDecimal.multiply(a,b,c)
division divide
a: string dividend
b: sting divisor
c: num precision
bigDecimal.divide(a,b,c)
example
download link:
at last
If you find it useful, remember to like, follow and collect~