Parsing decimal places in between
<input value="123" /> <span></span> $('input').change(function (){ var val = $(this).val().toFixed(2); $('span').text(val); }); I tried the code above, but I can’t get the decimal value on text() , it just displays as 123. This is my first experiment with the toFixed() tag
just in case toFixed() is a native js method, not jquery
+4
3 answers
toFixed is a method that you call by number, not by line. You need to parse the string into a number:
var val = parseFloat($(this).val(), 10).toFixed(2); Live demo here: http://jsfiddle.net/QrW5C/
+12
You need to parse it:
var NumericValue = parseFloat($(this).val()) var val = NumericValue .toFixed(2); info here: http://www.bennadel.com/blog/1013-Javascript-Number-toFixed-Method.htm
and
<span></spam> (?) 0