Hello,
I have a web form in which I have an input field that masks the user input to a certain format ("#.##0,00"). To do this, I had to hide the original input field and create a new one:
//hide base field
$(baseImponible).hide();
//create new masked base
let maskedBase = document.createElement("input");
maskedBase.className = "form-control";
maskedBase.id = "maskedBase";
//add function to base to set its mask and to calculate the total using the field "iva"
maskedBase.oninput = () => {
console.log("Mascara de Base Imponible");
let newValue = parseFloat($("#maskedBase").val().replace(/\D/g, '')) / 100;
$(baseImponible).val(newValue.toFixed(2));
console.log("Base imponible: ", $(baseImponible).val());
let calculatedValue = (1 + parseFloat($(iva).val().replace(/\D/g, '')) / 100) * newValue;
calculatedValue = calculatedValue.toFixed(2);
$(importeTotal).val(calculatedValue);
console.log("Importe total: ", calculatedValue);
console.log($(importeTotal).val());
}
//apply mask to base
$(maskedBase).mask(decimalFormat, {reverse: true});
//insert masked base
$(maskedBase).insertAfter($(baseImponible));
let baseImponible = "#cr027_baseimponiblenumber";
Everything logs properly, as it should. However, when I checked the value that's stored in the database I saw the decimals were ignored and added two empty decimals. The column value type is Float.
Actual behaviour:
User inputs 100.000,02
System stores 10.000.002,00
Expected behaviour:
User inputs 100.000,02
System stores 100.000,02
How can I fix this? How can I save the value I want into the corresponding column?
Thanks in advance!

Report
All responses (
Answers (