Skip to content

Instantly share code, notes, and snippets.

@JaosnHsieh
Created July 11, 2016 13:03
Show Gist options
  • Save JaosnHsieh/759b9b2cbafc9cff3f11db7f1794222d to your computer and use it in GitHub Desktop.
Save JaosnHsieh/759b9b2cbafc9cff3f11db7f1794222d to your computer and use it in GitHub Desktop.
ES6 and older version
//es6
const fixMe = (num, fix) => Math.round(num * 10 ** fix) / (10 ** fix)
fixMe(48.48-66.11111111, 2)
//older version
var fixme=function(num, fix) {
var answer = Math.round(num*Math.pow(10, fix))/(Math.pow(10, fix));
console.log(answer);
};
fixme(1/3, 8); //=>0.33333333 (8 decimal places)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment