Last active
April 20, 2021 16:05
-
-
Save mauriciodarocha/45c1fe2f969ac233bab7559e44f81eb9 to your computer and use it in GitHub Desktop.
Formata o número com separação decimal no formato para o Brasil. "839,66,123,1,234,560.0000000001" => "839.661.231.234.560,0000000001"
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
/** | |
Converte número separados por vírgulas p/ pontos, e decimal por vírgula. | |
string valor | |
Ex. formatNumberBR("839,66,123,1,234,560.0000000001") => "839.661.231.234.560,0000000001" | |
*/ | |
function formatNumberBR(valor) { | |
return valor.replace(/\./g, '|').replace(/,/g, '').replace(/(\d)(?=((\d{3})+)(?:\|))/g, '$1.').replace(/\|/g, ','); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment