-1
I am developing a project and need to calculate the percentage of spread (profit on sale) example: (1 Eth): 107.178552387 which in case is $107.18 with a 5% spread (ie 5% profit on top of the total price on Eth) and soon after need to add 2.5% fee on top of the total amount (amount of Eth + % spread), how could I do this in javascript ? a below a "pseudo code" in javascript to illustrate better.
$(function() {
$('#calc_input').keyup(function() {
var x = parseFloat($(this).attr('data-unitprice')),
y = parseFloat($(this).val()),
cot = y * x;
$('#resucota').attr('value', cot);
});
});
$(function() {
$('#spread').keyup(function() {
var z = parseFloat($(this).val());
var a = parseFloat($('#resucota').val());
var spread = z % a;
$('#lucro').attr('value', spread);
var total = 2.5% + spread
$('#resucota').attr('value', total);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row justify-content-center" id="sone" style="">
<div class="col-md-11 ">
<div class="input-group input-group-lg">
<div class="input-group-prepend">
<span class="input-group-text unit unidade moedsele" style="text-transform: uppercase;" id="inputGroup-sizing-sm">eth</span>
</div>
<input id="calc_input" type="text" name="total1" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-lg" data-unitprice="107.178552387">
<span class="input-group-text" id="inputGroup-sizing-lg">SPREAD</span>
<input type="text" id="spread" class="form-control">
</div>
<hr>
<div class="input-group input-group-lg">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-lg">USD</span>
</div>
<input readonly="" id="resucota" name="total" type="text" class="col-sm-6" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-lg"> + 2.5% taxa
</div>
<br>
<div class="invertable-input">
<div class="suporte">
<div class="status_grupo">
<div class="status_titulo m treecolun">Mínimo</div>
<input id="min" disabled="" value="134.39278008" class="status_valor m treecolun">
<div class="status_titulo m treecolun">USD</div>
</div>
</div>
</div>
<br><br>
<div class="invertable-input">
<div class="suporte">
<div class="status_grupo">
<div class="status_titulo m treecolun">Lucro</div>
<input disabled="" id="cotacao" value="0" class="status_valor m treecolun">
<div class="status_titulo m treecolun">USD</div>
</div>
</div>
</div>
<br><br>
<div class="invertable-input">
<div class="suporte">
<div class="status_grupo">
<div class="status_titulo m treecolun">Cotação</div>
<input disabled="" id="cotacao" value="0" class="status_valor m treecolun">
<div class="status_titulo m treecolun">USD</div>
</div>
</div>
</div>
<br><br>
</div>
<button type="submit" class="btn btn-info btn-fill btn-wd">GERAR ORDEM</button>
</div>