Skip to content

Instantly share code, notes, and snippets.

@arosemena
Created October 7, 2014 20:30
Show Gist options
  • Save arosemena/eb8bad788adcca4d86eb to your computer and use it in GitHub Desktop.
Save arosemena/eb8bad788adcca4d86eb to your computer and use it in GitHub Desktop.
Javascript convert price to integer
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