I have a function that does the sum of values of a line, I would like to know if it is possible to put the value as currency like this:
R$ 16,00
You're leaving this way
R$ 16.00
But I would not want to use third-party library.
My code:
var somaLinha = 0;
$('.columnRight > label').slice(-5).each(function( i, coluna ) {
var valorColuna = $(coluna).text().replace('R$', '').replace(',', '.');
valorColuna = parseFloat(valorColuna);
somaLinha += (!isNaN(valorColuna) ? valorColuna : 0);
});
if (somaLinha != 0) {
$('.columnRight > label').last().text('R$ ' + parseFloat(somaLinha, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")).toString();
}