Last active
December 1, 2016 09:34
-
-
Save rijkvanzanten/0a1fd8b9aef9cc7dca7aa6e80ad7eb9b to your computer and use it in GitHub Desktop.
Nice little function to format prices
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
function formatPrice(price, currency = 'USD', locale = 'en-US') { | |
const options = { style: 'currency', currency }; | |
const singles = price / 100; | |
if(singles % 1 === 0) options.maximumSignificantDigits = 0; | |
return singles.toLocaleString(locale, options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment