1
I have a input
which receives a user-typed value and an array of 12 values.. I am traversing the array with a Foreach.. because I need to find the approximate value of the value entered in input
.. I have the following code:
$('#possoPagar').keyup(function (e) {
let valor = $('#possoPagar').val();
let valorIdeal = 0;
$.each(parcelas, function (index, item) {
if (item.valor <= valor && item.valor >= valorIdeal) {
valorIdeal = item.valor;
$("#vParcela").html(parseFloat(item.valor).toFixed(2).replace('.', ','));
nParcelas.val(item.qtdParcelas);
}
});
});
The problem is that while it is less than the value of the parcel it does not recognize that parcel and sometimes it ends up bringing a value that is actually not the most approximate, Thank you!
It’s the closest up and down or just down?
– Sorack
Post the code so that we can execute and understand what you have already done. Create an example of the problem in jsfiddle or stacksnippet.
– Guilherme Nascimento