-
-
Save lpcuong2106/0e4dbfaea7257a550de44772ff50f981 to your computer and use it in GitHub Desktop.
Regular Expression to Format Currency In Javascript
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 formatCurrency(amount) | |
| { | |
| //truncate the amount to 0 decimals | |
| //for every digit that is followed by 3 digits and a word boundary | |
| //add a comma | |
| amount = amount.toFixed(0).replace(/(\d)(?=(\d{3})+\b)/g, "$1,"); | |
| return amount; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment