-1
I am trying to compare the selling price and the rate value over the selling price. example: the product costs 1467,73R$. my rate is 20%.In this case 20% above the price of the product would give 1761,276R$ I want that when entering the sale value(product price), the field cannot accept a Meno value that the sale price that should be 1761,276R$ why we added 20%. The error is that even typing a value above what was requested, the alert of which was typed a value less than the waiting continues to appear. I don’t know what I should do.Someone can help?
Now in Jquery:
$("#qty").click(function() {
var taxa = $("#taxa").val(); //0,2
var Price = $("#valor_tabela").val(); // 1467,73
var PriceHot = $("#valor_venda").val(value).val();
var totalTaxa = parseInt(taxa) * parseFloat(Price); //293,546
var percent = parseFloat(totalTaxa) + parseFloat(Price); //293,546 + 1467,73 =1761,276
if ($("#valor_venda").val() < percent) {
$('.enableOnInput').prop('disabled', true);
alert('O valor da venda é menor que o valor tabelado!');
} else {
$('.enableOnInput').prop('disabled', false);
var value = $("#valor_venda").val();
var primaryincome = $("#qty").val();
var otherincome = $("#valor_venda").val(value).val();
// Alterado o sinal de '+', para '*'
var totalincome = parseInt(primaryincome) * parseFloat(otherincome);
$("#result").val(totalincome);
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<div class="col-sm-3 ">
<label>Valor Tabelado</label>
<input type="text" class="form-control" name="valor_tabela" id="valor_tabela" value="1467,73" readonly>
<input type="text" class="form-control" name="taxa" id="taxa" value="0,2" readonly>
</div>
<div class="col-sm-3">
<label>Valor Venda</label>
<input type="text" class="form-control" placeholder="Valor venda em R$" name="valor_venda" id="valor_venda">
</div>
<div class="col-sm-3 ">
<label>Quantidade</label>
<input type="number" class="form-control calculate" id="qty" name="quantidade" value="0">
</div>
<div class="col-sm-3 mt-2 ">
<label>Sub Total</labe>
<input type="number" class="form-control" id="result" name="sub_total" readonly>
</div>
Already gets it wrong that monetary value should not be treated with
parseFloat()
, something like 1200,50 withparseFloat()
will become 1200.– Azzi
should be pasrInt() in case?
– Gladiador
No, he’ll turn his value into a whole, use
toLocaleString()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString– Azzi
@Developer.mozilla.org I tested by swapping everything in parsInt() and it worked only that of course I’ll have everything in one piece.but then I switched all variables with parseFloat() and it worked. thanks guys. you gave me a light to solve this problem and I thank you :)
– Gladiador
I recommend you put your answer to the question so it won’t be closed, keep in mind that it can help other people
– Azzi
@Azzi yes, I just posted. only that can only accept the answer in two days.
– Gladiador