Good morning everyone.
Next, I need to make when the user exits with the focus of the field or when typing it, format this field according to the format of money, first in the Brazilian format.
Example: 14700.25 or 14.00. Without the dots, if not AngularJS can not add.
But using the code below, the toFixed (2) function removes the zeros from the decimal places and for example if the user informs 32, it even adds the two zeros after the comma, however when modifying in the model continues 32 and not 32.00. And if you do not put parseFloat when modifying the model, the field is blank.
Follow the code:
function formatarNumero(id, campo){
var scope = angular.element(document.getElementById('divVendaProdutos')).scope();
var valor_campo;
if (campo == 1){
valor_campo = $('#quantidade' + id)[0].value;
var amt = parseFloat(valor_campo);
amt = amt.toFixed(2);
scope.$apply(function () {
scope.invoice.items[id].quantidade = parseFloat(amt);
});
}
if (campo == 2){
valor_campo = $('#valorUnitario' + id)[0].value;
var amt = parseFloat(valor_campo);
amt = amt.toFixed(2);
scope.$apply(function () {
scope.invoice.items[id].valorUnitario = parseFloat(amt);
});
}
}
What is the best way to solve this problem?
Thank you in advance.