Skip to content

Instantly share code, notes, and snippets.

@joadr
Last active October 6, 2016 01:54
Show Gist options
  • Save joadr/4e8c782436720bb5db5af87b0821f0c4 to your computer and use it in GitHub Desktop.
Save joadr/4e8c782436720bb5db5af87b0821f0c4 to your computer and use it in GitHub Desktop.
Gist to truncate a chilean format.
// Original price
var price = '$2.968.945'
// remove $ and .
price = price.replace(/\$/g,'').replace(/\./g,'')
// convert to Int
price = parseInt(price)
// Divide by 1000 and truncate to remove extra digits
price = Math.trunc(price/1000)
// Format the final price
price = price*1000-10
// Price output --> 2967990
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment