Last active
August 6, 2019 20:12
-
-
Save jhowbhz/6938b488674628e49e25799e42830835 to your computer and use it in GitHub Desktop.
format BRL 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 transform BRL em DECIMAL // R$ 1.000,00 em 1000.00 | |
function formatMoeda(get_valor) { | |
replace = get_valor.replace('.', ''); | |
retorno = replace.replace(',', '.'); | |
return retorno; | |
} | |
// set front-end money BRL (R$) JavaScript | |
var valor = 568.5; | |
// set value BRL with (R$) | |
var valorFormatado = valor.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }); | |
alert('O valor formatado de ' + valor + ' é ' + valorFormatado); | |
// set value without (R$) | |
var valorFormatado2 = valor.toLocaleString('pt-BR', { minimumFractionDigits: 2}); | |
alert('O valor formatado sem o cifrão de ' + valor + ' é ' + valorFormatado2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment