Reputation: 747
I have an input field that is used to insert a dollar amount. If the user types in "100" or "100." I want to add two decimal places to the value using the toFixed(2) method.
Here is an example
This is what I have tried:
var j$ = jQuery.noConflict();
j$(document).ready(function() {
j$('#ccAmt').blur(function() {
j$(this).val(j$(this).val().toFixed(2));
});
});
I found several examples on the forum, but everything I tried didn't work. What am I missing?
Thanks.
Upvotes: 1
Views: 557
Reputation: 206514
var j$ = jQuery.noConflict();
j$(document).ready(function($) {
$('#ccAmt').blur(function() {
var val = parseFloat( this.value ).toFixed(2);
$(this).val( val );
});
})(jQuery);
Upvotes: 2
Reputation: 4024
Is .val()
returning a Number? Try:
j$(this).val(parseFloat(j$(this).val()).toFixed(2));
Upvotes: 4