I try to get a decimal value for further calculation in jquery.
var vatPercentageString = $("#Price").val();
var percentage = parseFloat(vatPercentageString).toFixed(2);
But even if I have the value "12,34" in the "Price" textbox I only get 12 as the percentage value, why is that?
>Solution :
Because , is not proper symbol for decimals separator. You should first replace it by .:
function changed() {
var vatPercentageString = $("#Price").val().replace(',', '.');
var percentage = parseFloat(vatPercentageString).toFixed(2);
console.log(percentage);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<input type="text" id="Price" onchange="changed()" />