Skip to content

Instantly share code, notes, and snippets.

@CodySwannGT
Created September 28, 2019 14:59
Show Gist options
  • Save CodySwannGT/1988e9f63c46b12d2efad1d477290b2f to your computer and use it in GitHub Desktop.
Save CodySwannGT/1988e9f63c46b12d2efad1d477290b2f to your computer and use it in GitHub Desktop.
formatOdds.js
// (Collect Amount - Bet Amount) / Bet Amount
// Ex: If the Collect Amount is $1,000 and the Bet Amount is $100, then the Odds are 9.00/1
// IF the Odds are less than 1.00, then there is a different formula of:
// (1/((Collect Amount - Bet Amount) / Bet Amount)) * -100.00
// Ex: If the Collect Amount is $900 and the Bet Amount is $600, then the Odds are -200.00
const formatOdds = (collectAmount, betAmount) => {
const collect = parseFloat(collectAmount)
const bet = parseFloat(betAmount);
const odds = (collect - bet) / bet;
if(odds < 1.0) {
return parseFloat((1.0 / odds) * -100).toFixed(2)
}
return `${odds.toFixed(2)}/1`
}
export default formatOdds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment