I have a input text field which users can input a number and for a currency.
<input type="text" name="com-uprice" value="">
I used this snippet to add a comma for every 3 digits
$('input[name="com-uprice"]').keyup(function(event) {
// skip for arrow keys
if(event.which >= 37 && event.which <= 40) return;
// format number
$(this).val(function(index, value) {
return value
.replace(/\D/g, "")
.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
console.log(this.val)
});
});
Now I need that value into a number for computation purposes I used this line of code to convert it into a number
parseInt($('input[name="com-uprice"]').val().replace(',', ''))
It returns a number but not the whole number that users inputted.
For example.
If I input 1,000,000
It returns like 1000
only