Created
July 11, 2016 13:03
-
-
Save JaosnHsieh/759b9b2cbafc9cff3f11db7f1794222d to your computer and use it in GitHub Desktop.
ES6 and older version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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