Bet
Bet
by Mingtao Sun
HTML
Odds 1 : <input id="odds-1" /> Odds 2: <input id="odds-2" /> Commission: <input id="commission" value="5"/> Bonus bet <input id="bonus-bet" value="100">
<br/>
Converstion rate: <span id="convert-rate"></span>
<br/>
Real money to bet: <span id="real-money"></span>
<br/>
margin: <span id="margin"></span>
JavaScript
$(function($){
$('input').focusout(function(){
calculate();
});
});
function calculate(){
var odds1 = $('#odds-1').val();
var odds2 = $('#odds-2').val();
var commission = $('#commission').val();
var bigOdds = Math.max(odds1, odds2);
var smallOdds = Math.min(odds1, odds2);
if ($.isNumeric(bigOdds) && $.isNumeric(smallOdds) && $.isNumeric(commission)){
smallOdds = getRealSmallOdds(smallOdds, commission);
var conversionRate = (bigOdds - 1) * (smallOdds - 1) / smallOdds;
$('#convert-rate').html(conversionRate.toFixed(2));
var bonusBet = $('#bonus-bet').val();
var realMoney = (bigOdds - 1) * bonusBet / smallOdds;
$('#real-money').html(realMoney.toFixed(2));
var margin = bigOdds * smallOdds / (bigOdds + smallOdds);
$('#margin').html(margin.toFixed(2));
}else{
$('#convert-rate').html('');
$('#real-money').html('');
$('#margin').html('');
}
}
function getRealSmallOdds(smallOdds, commission){
return (1 - commission / 100) * (smallOdds - 1) + 1;
}