Last active
March 11, 2024 12:47
-
-
Save rodrigodiasnoronha/e3f2aa71828e05c3a5261b46b69f9c33 to your computer and use it in GitHub Desktop.
Currency Mask
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
| const formatCurrency = (numberString = "") => { | |
| let mask = numberString.replace(",", "").replace(".", "").replace(/\D/g, ""); | |
| const options = { minimumFractionDigits: 2 }; | |
| const result = new Intl.NumberFormat("pt-BR", options).format(parseFloat(mask) / 100); | |
| if (result === "NaN") { | |
| return ""; | |
| } | |
| return result; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment