Created
October 24, 2016 12:55
-
-
Save gskema/c06a3dd8a1c8a3c859cb7152e656350d to your computer and use it in GitHub Desktop.
Correctly rounds JavaScript number (float) to 2 decimals.
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
function roundFloat(number, decimals) { | |
return (Math.round(number * (Math.pow(10, decimals))) / Math.pow(10, decimals)).toFixed(decimals) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment