Created
October 1, 2014 02:48
-
-
Save hongkheng/00463561136dbb5dd8ac to your computer and use it in GitHub Desktop.
Round number to specific number of decimal places
This file contains 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
// 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