parseFloat
doesn't understand commas (,
), per the spec:
If parseFloat
encounters a character other than a plus sign (+
), minus sign (-
U+002D HYPHEN-MINUS), numeral (0
–9
), decimal point (.
), or exponent (e
or E
), it returns the value up to that character, ignoring the invalid character and characters following it.
So you'll need to replace any commas with decimal points if you'd like to parse them as a number.
// After getting our value, replace `,` with `.`
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.1/jquery.min.js"></script>
<label>Price: <input id="Price" value="12,34"></label>