Created
August 8, 2012 04:26
-
-
Save sn00011/3292016 to your computer and use it in GitHub Desktop.
[Javascript] Round a number to a specified decimal place
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
/** | |
* Round a number to a specified decimal place. | |
* @var num The number to be rounded | |
* @var digits The digit behind the decimal point to be rounded to | |
*/ | |
function roundNumber(num, digits) { | |
num = parserFloat(num); | |
var multiple = Math.pow(10, digits); | |
return Math.round(num * multiple) / multiple; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment