Created
October 7, 2014 20:30
-
-
Save arosemena/eb8bad788adcca4d86eb to your computer and use it in GitHub Desktop.
Javascript convert price to integer
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
toIntPrice = (number)-> | |
price = number.match /(\d+)(\.\d{1,2})?/ | |
if price[2] | |
price[2] = price[2].replace /\./g, '' | |
console.log price | |
if price[2].length == 1 then price[2] += '0' | |
else price[2] = '00' | |
if price then price = price[1] + price[2] else price = 0 | |
return price |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment