Last active
August 1, 2019 04:46
-
-
Save fczbkk/ab7b65bf8ce2f3e348de795597afe48f to your computer and use it in GitHub Desktop.
Simple currency formatter
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 formatAsCurrency (value = 0, currency = '$') { | |
const formattedValue = (value/100).toFixed(2) | |
return currency + formattedValue | |
} | |
formatAsCurrency(100) | |
// $1.00 | |
formatAsCurrency(123) | |
// $1.23 | |
formatAsCurrency(456, '€') | |
// €4.56 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment