I have a input
which receives a value entered by the user and an array with 12 values .. I'm traversing the array with a ForEach .. since I need to find the approximate value of the value typed 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 installment it does not recognize that portion and sometimes it ends up bringing a value that is not really the closest, Thanks!