A micro library truly working around floating-point precision issue in javascript, like

  • 0.1*0.2 = 0.020000000000000004
  • 0.1+0.2 = 0.30000000000000004

jsprec.js doesn't cheat just with rounding the result. It implements an addition and a multiplication operations: first it converts the numbers to strings, multiplies the numbers by the required power of 10 using only string operations, adds/mults the numbers, then divides the result by the required power of 10 - with only string operations again.

Just link jsprec.js and call Number.mult(0.1,0.2) and Number.add(0.1,0.2)

download jsprec library