Skip to content

Instantly share code, notes, and snippets.

@grippado
Created September 13, 2022 14:59
Show Gist options
  • Save grippado/2b63780230f5b9b5a071adcbffa0e836 to your computer and use it in GitHub Desktop.
Save grippado/2b63780230f5b9b5a071adcbffa0e836 to your computer and use it in GitHub Desktop.
let formatMoneyToCents = function(value) {
value = (value + '').replace(/[^\d.-]/g, '')
if (value && value.includes('.')) {
value = value.substring(0, value.indexOf('.') + 3)
}
return value ? Math.round(parseFloat(value) * 100) : 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment