Reputation: 155
so I'm making this calculator thing and I've come across an issue, when I store the value of input type number in another variable it comes missing a number like this picture:
so the getValue() function gets the fraction of a number or a string and here's its code:
function getValue(v) {
return +v.toString().match(/\.(\d*)/)[1] || 0;
}
Anyway if I got this issue fixed I think I could finally finish this application, so any help would be appreciated and thanks in advance.
Edit: I forgot to add the code that stores the value of the input, so here it is:
input.addEventListener("keypress", function() {
num = input.value * 1;
re1 = input.value;
});
Upvotes: 0
Views: 19
Reputation: 14198
You should use keyup
event instead of keypress
function getValue(v) {
return +v.toString().match(/\.(\d*)/)[1] || 0;
}
$("input").on("keyup", function() {
num = $(this).val() * 1;
re1 = $(this).val();
console.log(re1);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input />
Upvotes: 1