Format an html form input as a currency

Asked

Viewed 749 times

0

Please someone can help me, I’m not able to format an input as currency.

<label for="saldoInicial">Saldo Inicial</label>
<input type="number" format="currency" precision="2" id="valorSaldoInicial" name="valorSaldoInicial" class="form-control" formControlName="valorSaldoInicial" />

inserir a descrição da imagem aqui

1 answer

1


Javascript has an internal function for this. Number.prototype.toLocaleString

var valor = 16.00;
var texto = valor.toLocaleString("pt-BR", 
     { style: "currency" , currency:"BRL"});

console.log(texto);

Source: /a/102582

Browser other questions tagged

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