PHPackages                             gryfoss/odds - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. gryfoss/odds

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

gryfoss/odds
============

PHP package for dealing with different formats of betting odds: decimal (European), fractional (British), and moneyline (American)

v3.0.0(6mo ago)035MITPHPPHP ^8.4CI passing

Since Aug 19Pushed 6mo agoCompare

[ Source](https://github.com/GryfOSS/odds)[ Packagist](https://packagist.org/packages/gryfoss/odds)[ RSS](/packages/gryfoss-odds/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (5)Used By (0)

Odds Formatter
==============

[](#odds-formatter)

[![Tests](https://github.com/gryfoss/odds/workflows/Tests/badge.svg)](https://github.com/gryfoss/odds/actions)[![Coverage](https://camo.githubusercontent.com/32855e94577df9d0a30995653b17d33a5fbfdf644518f96ea0374313397d19b7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e)](https://github.com/gryfoss/odds/actions)[![PHP Version](https://camo.githubusercontent.com/29410bb6bcb6a3fb064bad25ef3ce0793978e60c3876a15c4c80f62d6660e553/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e342532422d626c7565)](https://php.net)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

PHP package for dealing with different formats of betting odds: decimal (European), fractional (British), and moneyline (American).

🚀 New Architecture (v2.0)
-------------------------

[](#-new-architecture-v20)

This library has been completely redesigned with:

- **Immutable `Odds` class** containing all formats and probability (not meant for direct instantiation - use `OddsFactory`)
- **`OddsFactory`** with dependency injection for conversion strategies
- **String-based decimals** for precision and security (no more float issues!)
- **bcmath calculations** for exact mathematical operations
- **Extensible odds ladder system** via interfaces
- **Fixed precision integer support** for performance-critical applications

Features
--------

[](#features)

- ✅ **Precision**: String-based decimals with bcmath calculations
- ✅ **Immutable design**: Thread-safe odds objects
- ✅ **All-in-one**: Single object contains decimal, fractional, moneyline, and probability
- ✅ **Dependency injection**: Configurable conversion strategies
- ✅ **Extensible**: Custom odds ladder implementations
- ✅ **Comprehensive**: Full test coverage

Requirements
------------

[](#requirements)

- PHP 8.4+ (required for bcmath precision functions)
- bcmath extension (standard in most installations)
- Composer

Installation
------------

[](#installation)

```
composer require gryfoss/odds
```

Quick Start
-----------

[](#quick-start)

```
require 'vendor/autoload.php';

use GryfOSS\Odds\OddsFactory;

$factory = new OddsFactory();

// Create from string decimal (secure, precise)
$odds = $factory->fromDecimal('2.50');

echo $odds->getDecimal();     // "2.50"
echo $odds->getFractional();  // "3/2"
echo $odds->getMoneyline();   // "+150"
echo $odds->getProbability(); // 40 (integer percentage)
```

Usage Examples
--------------

[](#usage-examples)

### Basic Conversions

[](#basic-conversions)

```
$factory = new OddsFactory();

// From decimal
$odds = $factory->fromDecimal('1.75');

// From fractional
$odds = $factory->fromFractional(3, 4);

// From moneyline
$odds = $factory->fromMoneyline('-133');

// From fixed precision integer (advanced usage)
$odds = $factory->fromFixedPrecision(250); // Represents 2.50
```

### With Odds Ladder

[](#with-odds-ladder)

```
use GryfOSS\Odds\Utils\OddsLadder;

$oddsLadder = new OddsLadder();
$factory = new OddsFactory($oddsLadder);

$odds = $factory->fromDecimal('2.00');
echo $odds->getFractional(); // Uses odds ladder lookup
```

### Custom Odds Ladder

[](#custom-odds-ladder)

```
use GryfOSS\Odds\Utils\OddsLadder;

class MyCustomLadder extends OddsLadder
{
    protected function getLadder(): array
    {
        return [
            '1.50' => 'evens',
            '2.00' => '1/1',
            '3.00' => '2/1',
        ];
    }
}

$factory = new OddsFactory(new MyCustomLadder());
$odds = $factory->fromDecimal('1.90');
echo $odds->getFractional(); // "evens"
```

### Working with Fixed Precision Integers

[](#working-with-fixed-precision-integers)

For performance-critical applications, you can work directly with fixed precision integers (decimal \* 100):

```
$factory = new OddsFactory();

// Create from already prepared integer (2.50 = 250)
$odds = $factory->fromFixedPrecision(250);
echo $odds->getDecimal();           // "2.50"
echo $odds->getFixedPrecisionOdds(); // 250

// Useful for database storage or API responses
$integerOdds = $odds->getFixedPrecisionOdds(); // Store as integer
$restoredOdds = $factory->fromFixedPrecision($integerOdds); // Restore later
```

Migration from old `odds-formatter`.
------------------------------------

[](#migration-from-old-odds-formatter)

See [STRING\_DECIMAL\_GUIDE.md](STRING_DECIMAL_GUIDE.md) for detailed migration instructions.

**Key Changes:**

- Use `OddsFactory` instead of individual odd classes
- Pass decimals as strings: `'2.50'` instead of `2.50`
- All return values are strings for precision (except `getProbability()` which returns integer)
- Single `Odds` object contains all formats
- `Odds` class is immutable and should not be instantiated directly

Documentation
-------------

[](#documentation)

- [String Decimal Guide](STRING_DECIMAL_GUIDE.md) - Precision and migration
- [NEW\_API.md](NEW_API.md) - Complete API documentation

License
-------

[](#license)

This is an open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance69

Regular maintenance activity

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~87 days

Total

2

Last Release

183d ago

Major Versions

v2.0.0 → v3.0.02025-11-14

PHP version history (2 changes)v2.0.0PHP ^8.2

v3.0.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/b76a5fac115d24d698d09cc939a6922bf309732ae61d0f2f215ae9e7397658ea?d=identicon)[ideaconnect](/maintainers/ideaconnect)

---

Top Contributors

[![alexsabdev](https://avatars.githubusercontent.com/u/14823114?v=4)](https://github.com/alexsabdev "alexsabdev (12 commits)")[![drabarek](https://avatars.githubusercontent.com/u/7080725?v=4)](https://github.com/drabarek "drabarek (2 commits)")[![bpacholek](https://avatars.githubusercontent.com/u/3039162?v=4)](https://github.com/bpacholek "bpacholek (1 commits)")

---

Tags

bettingoddsdecimal oddeuropean oddfractional oddbritish oddamerican oddmoneyline odd

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/gryfoss-odds/health.svg)

```
[![Health](https://phpackages.com/badges/gryfoss-odds/health.svg)](https://phpackages.com/packages/gryfoss-odds)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
