I have a function bound to the blur event for a specific class (attached to number type inputs) that is intended to force two decimal places. The following function works in Chrome, but does not work in Firefox.
Code:
/**
* Force 2 decimal places for specified inputs
*
*/
$(document).on('blur', '.to-dec', function() {
// get value
var value = $(this).val();
// no value
if (!value) return;
// cast to 2 decimal places
value = parseFloat(value).toFixed(2);
// update value
$(this).val(value);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" class="to-dec" min="0" step="0.01" required>
If I output value before it is set, I get the expected value (ie. 3.00 for an input value of 3).
Anyone know why Firefox would be preventing this value to be set? I've already tried to use parseFloat() when setting the value with val().
Thanks!
type=number