Skip to content

Instantly share code, notes, and snippets.

@sn00011
Created August 8, 2012 04:26
Show Gist options
  • Save sn00011/3292016 to your computer and use it in GitHub Desktop.
Save sn00011/3292016 to your computer and use it in GitHub Desktop.
[Javascript] Round a number to a specified decimal place
/**
* 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