Skip to content

Instantly share code, notes, and snippets.

@wjmazza
Last active August 29, 2015 14:05
Show Gist options
  • Save wjmazza/aeec68c1c48e45033d69 to your computer and use it in GitHub Desktop.
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)
// 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