How do I convert integer and dot numbers into real currency e.g.: 10.00

Asked

Viewed 47 times

-4

I would like to convert this code it only ta appearing numbers with dot for example 8.66, 8, 8.95, 9...

i would like to leave in Brazilian real ex.: R$8,66

<script>
obj.totalCart = function() {
    var totalCart = 0;
    for(var item in cart) {
      totalCart += cart[item].price * cart[item].count;
    }
    return Number(totalCart.toFixed(2));
  }
</script>

1 answer

0


Consider that your question already exists here and here and here

Here are some ways to do it:

var atual = 8.66;

//Formato com R$
var f = atual.toLocaleString('pt-br',{style: 'currency', currency: 'BRL'});

//Formato sem R$
var f2 = atual.toLocaleString('pt-br', {minimumFractionDigits: 2});

console.log(f);
console.log(f2);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.