Skip to content

Instantly share code, notes, and snippets.

@hongkheng
Created October 1, 2014 02:48
Show Gist options
  • Save hongkheng/00463561136dbb5dd8ac to your computer and use it in GitHub Desktop.
Save hongkheng/00463561136dbb5dd8ac to your computer and use it in GitHub Desktop.
Round number to specific number of decimal places
// Rounds a target number to a specific number of decimal places.
function roundToPrecision(numberVal:Number, precision:int = 0):Number
{
var decimalPlaces:Number = Math.pow(10, precision);
return Math.round(decimalPlaces * numberVal) / decimalPlaces;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment