私のコードは正常に動作しますが、#chance に 60.1、60.2、60.3 などの 10 進数が入力されると、利益と支払いが台無しになります。
例: チャンスには 60%、ベットには 1 を入力します。支払いには 1.65、利益には 0.65 を返します。それはすべて正しいです。
しかし、60.1 を入力すると、16.5 (間違った小数) と 15.5 の利益が返されます。16.5 は簡単な修正のように思えますが、修正方法はわかりませんが、利益のために 15.5 を返す理由がわかりません。支払いを修正すれば、利益の問題が修正されるのではないかと考えました。
どうしたの?
ありがとう。
<script>
$(document).ready(function(){
function updateValues() {
// Grab all the value just incase they're needed.
var chance = $('#chance').val();
var bet = $('#bet').val();
var pay = $('#pay').val();
var profit = $('#profit').val();
// Calculate the new payout.
var remainder = 101 - chance;
pay = Math.floor((992/parseFloat((chance+0.5))) *100)/100;
// Calculate the new profit.
profit = bet*pay-bet;
profit = profit.toFixed(6);
// Set the new input values.
$('#chance').val(chance);
$('#bet').val(bet);
$('#pay').val(pay);
$('#profit').val(profit);
}
parseInt($('#chance').keyup(updateValues));
parseInt($('#bet').keyup(updateValues));
parseInt($('#pay').keyup(updateValues));
parseInt($('#profit').keyup(updateValues));
});
</script>