Dealing with float precision in Javascript
From this post: How to deal with floating point number precision in JavaScript? You have a few options: Use a special datatype for decimals, like decimal.js Format your result to some fixed number of significant digits, like this: (Math.floor(y/x) * x).toFixed(2) Convert all your numbers to integers