Last active
August 29, 2015 14:05
-
-
Save wjmazza/aeec68c1c48e45033d69 to your computer and use it in GitHub Desktop.
parseDecimal - returns number value to the right of the decimal point (en-US)
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
// not tested for localized usage, developed for en-US | |
function parseDecimal(numberVal) { | |
var modValue = numberVal % 1, // returns modulous of number | |
wholeNumber = numberVal - modValue, // returns the whole number | |
wholeNumberLength = wholeNumber.toString().length, // amount of digits in number | |
decimalLength = numberVal.toString().length - wholeNumberLength - 1, // amount of digits after decimal (-1 for decimal itself) | |
decimalNumber = Math.round(modValue * Math.pow(10,decimalLength)); // fix decimal places to original length and remove decimal point | |
return decimalNumber; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment