<input value="123" />
<span></span>
$('input').change(function (){
var val = $(this).val().toFixed(2);
$('span').text(val);
});
I have tried the code above but can't seem to get the decimal on the text()
is just shows as 123. This is my first time experimentind with toFixed()
just in case toFixed()
is a js
native method not a jquery
toFixed
is a method that you would call on a number, not on a string. You need to parse the string to a number:
var val = parseFloat($(this).val(), 10).toFixed(2);
Live demo here: http://jsfiddle.net/QrW5C/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With