Created
March 28, 2018 03:55
-
-
Save shansana/def7967d1580cb7e442fc3a1d83037b8 to your computer and use it in GitHub Desktop.
Format value to currency, thousands separator and 2 decimal places
This file contains hidden or 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 currency(value) { | |
return value.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); | |
} | |
console.log(currency(1000.5)); | |
// logs 1,000.50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment