4
I need to convert for example the value "025" for "0.25" or "005" for "0.05":
I’m trying to do it this way:
var valor1 = $("#ValorDesconto").val().replace(/[^\d]+/g,'');
parseFloat(valor1).toFixed(2)
How do I ? the way I did above is always added two zeros to the right: for example: of "025" for "25.00" or "005" for "5.00".
Here is the full code:
var valor1 = $("#ValorUnitario").val().replace(/[^\d]+/g,'');
var valor2 = $("#ValorDesconto").val().replace(/[^\d]+/g,'');
var _produto = {
"PaoID": $("#SelPao").val(),
"FermentacaoID": $("#SelFermentacao").val(),
"Observacao": $("#Observacao").val(),
"Status": true,
"ValorUnitario": Number(valor1).toFixed(2),
"ValorDesconto": Number(valor2).toFixed(2)
};
console.log(_produto);
$.ajax({
url: "/Administrativo/Produto/SalvarJSON",
type: "POST",
dataType: "JSON",
contentType: "application/json charset=utf-8",
processData: false,
data: JSON.stringify(_produto),
beforeSend: function () {
},
complete: function () {
},
success: function (data) {
if (data.ok == true) {
window.location.href = "/Administrativo/Produto/Index";
} else {
$("#advertenciaModal .modal-body").html("<div>" + data.msg + "</div>");
$("#advertenciaModal").modal();
};
},
error: function (result) {
window.location.href = "/Administrativo/Produto/Index";
}
});
I used Number(valor1).toFixed(2)
as suggested by Otto but without effect
I edited the question with the suggestion and it didn’t work.
– hard123
@Adrianosuv funny that in the print appears right, the error is of an image that is missing.
– Otto
Hello @Otto the way you posted there is no error, the problem is that it does not convert the way you want if you look at the print we have for example Valordesconto = "25,00" I implemented the Number function and typed in the input "0,25" and converted to "25,00".
– hard123