Created
October 26, 2012 18:11
-
-
Save sisiwei/3960393 to your computer and use it in GitHub Desktop.
Round any number and return with or without label
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
| /* PARAMS: | |
| number = the raw number, it can be a string | |
| decimaloutput = the number of decimal points you want it to return | |
| label = optional param, the label you want returned at the end like 'thousand' | |
| */ | |
| function roundNumber(number, decimaloutput, label){ | |
| var n = parseInt(number), | |
| s = n.toString(), | |
| c = s.length - 1, | |
| d = Math.pow(10, c), | |
| f = n/d; | |
| var output = (label == undefined) ? f.toFixed(decimaloutput) : f.toFixed(decimaloutput) + ' ' + label; | |
| return output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment