I need to convert for example the value "025" for "0.25" or "005" for "0.05" :
I'm trying to do it like this:
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: example: from "025" to "25.00" or "005"
Here is the complete 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 Otto's suggestion but no effect