betting-odds-converter
v1.0.1
Published
Convert betting odds between decimal, fractional, American and implied probability formats. Payout and bookmaker margin calculators included. Zero dependencies.
Downloads
23
Maintainers
Readme
betting-odds-converter
Convert betting odds between decimal, fractional, American and implied probability formats. Includes payout and bookmaker margin (overround) calculators. Zero dependencies, ~2 KB.
🖥 Try it in the browser: Betting Odds Converter (free tool, no signup)
Install
npm install betting-odds-converterUsage
import {
toDecimal,
fromDecimal,
payout,
bookmakerMargin,
} from 'betting-odds-converter';
// Parse any format to decimal odds
toDecimal('+150', 'american'); // 2.5
toDecimal('3/2', 'fractional'); // 2.5
toDecimal('40%', 'probability'); // 2.5
toDecimal('2,50', 'decimal'); // 2.5 (comma tolerated)
// Convert decimal odds to every format
fromDecimal(2.5);
// { decimal: 2.5, fractional: '3/2', american: 150, impliedProbability: 40 }
// Payout for a stake
payout(100, 2.5);
// { stake: 100, totalReturn: 250, profit: 150 }
// Bookmaker margin (overround) of a market
bookmakerMargin([1.9, 2.0]);
// { totalImpliedProbability: 102.63…, marginPercent: 2.63…, fairOdds: [1.95, 2.05…] }API
| Function | Description |
|---|---|
| toDecimal(value, format) | Parse "decimal", "fractional", "american" or "probability" input to decimal odds. Returns NaN on invalid input. |
| decimalToFractional(d) | 2.5 → "3/2" (simplified fraction) |
| decimalToAmerican(d) | 2.5 → 150, 1.5 → -200 |
| impliedProbability(d) | 2.5 → 40 (percent) |
| fromDecimal(d) | All formats at once |
| payout(stake, d) | Stake, total return and profit |
| bookmakerMargin(oddsArray) | Total implied probability, margin % and fair odds of a market |
Formulas
implied probability = 1 / decimal × 100
fractional = (decimal - 1) as a simplified fraction
american = decimal >= 2 ? (decimal - 1) × 100 : -100 / (decimal - 1)
margin (overround) = (Σ 1/odds - 1) × 100Related tools
Free, open-source, browser-based tools by the same maintainers:
- Betting Odds Converter — this library, as a web tool
- Provably Fair Verifier — verify crypto casino game outcomes
- House Edge Calculator — true cost of casino games
License
MIT — see LICENSE.
