> ## Documentation Index
> Fetch the complete documentation index at: https://hedgeem-api.qeetoto.com/llms.txt
> Use this file to discover all available pages before exploring further.

# F033 — Rounding Algorithms

> Odds rounding to player-friendly values; affects displayed odds and actual RTP

# F033 — Rounding Algorithms

| Field  | Value                       |
| ------ | --------------------------- |
| ID     | F033                        |
| Phase  | 4 — Configuration           |
| Jira   | TBD — create from HEDGE-133 |
| Status | TS ⬜ · JS ⬜ · UMA ⬜         |

## Business Rule

A **Rounding Algorithm** converts the precise computed payout odds (`oddsActual`) into a player-friendly rounded value (`oddsRounded`). Rounding is optional — enabled or disabled by the operator at installation.

**Example:**

| `oddsActual` | Rounding mode   | `oddsRounded`             |
| ------------ | --------------- | ------------------------- |
| 3.71         | Integer         | 3                         |
| 3.71         | 1 decimal place | 3.7                       |
| 3.88         | Integer         | 3                         |
| 3.88         | 1 decimal place | 3.9                       |
| 2.978        | 1 decimal place | 2.9 (as seen in coredata) |

**RTP impact:** Rounding down (the typical direction for player-friendly presentation) reduces actual RTP below target. This is expected and operator-accepted. Rounding mode selection is part of how the operator balances presentation quality against precise RTP targeting.

## Source: Game Concept Document

> "In Texas Hedge'Em context a 'Rounding Algorithm' is the term given to rounding the payout-odds presented to a player to an integer or whole-number-fraction. For example, instead of presenting odds of 3.71:1 the player would be presented odds of 3:1. Rounding Algorithms are optional and enabled or disabled at installation."

> "The target RTP is set by the operator at installation time but the actual RTP can be influenced by other configuration parameters such as 'Rounding Algorithms'."

## Evidence in Coredata

The coredata (ported from JS game records) shows both `oddsActual` and `oddsRounded` per hand per stage:

```typescript theme={null}
// game-engine/F001 example from coredata.ts
{ oddsActual: 2.978, oddsRounded: 2.9, ... }  // 1 d.p. rounding
{ oddsActual: 7.6965, oddsRounded: 7, ... }    // integer rounding
{ oddsActual: 3.0204, oddsRounded: 3, ... }    // integer rounding
```

The current coredata appears to use a mix of integer and 1 d.p. rounding. The precise algorithm used to generate this data is not yet documented.

## Rounding Modes (to be confirmed)

| Mode                  | Description                   | Example       |
| --------------------- | ----------------------------- | ------------- |
| Integer               | Round to nearest whole number | 3.71 → 4 or 3 |
| Integer (floor)       | Always round down             | 3.71 → 3      |
| 1 decimal place       | Round to 1 d.p.               | 3.71 → 3.7    |
| Whole-number fraction | Round to nearest 0.5 step     | 3.71 → 3.5    |

The exact algorithm(s) used in the JS reference implementation require server-side code audit.

## TypeScript Implementation

**Current status:** `oddsRounded` is consumed directly from pre-computed coredata. No rounding is performed client-side. The `oddsRounded` field already contains the rounded value.

Display in GameScene.ts (HEDGE-86 — suppress trailing .0):

```typescript theme={null}
const odds = info.oddsRounded;
const oddsStr = Number.isInteger(odds) ? `x${odds}` : `x${odds.toFixed(1)}`;
```

Full rounding algorithm implementation will be needed for live data generation.

## Acceptance Criteria

| #   | Criterion                                                        | JS  | TS  | UMA |
| --- | ---------------------------------------------------------------- | --- | --- | --- |
| AC1 | `oddsRounded` derived from `oddsActual` via configured algorithm | ⬜   | N/A | ⬜   |
| AC2 | Integer rounding mode: `oddsRounded` is a whole number           | ⬜   | ⬜   | ⬜   |
| AC3 | Displayed odds match `oddsRounded`, not `oddsActual`             | ⬜   | ✅   | ⬜   |
| AC4 | Rounding can be disabled (display `oddsActual` directly)         | ⬜   | ⬜   | ⬜   |
| AC5 | Trailing `.0` suppressed in display (x5, not x5.0)               | N/A | ✅   | ⬜   |

## Version Parity

| Version        | Status        | Notes                                                     |
| -------------- | ------------- | --------------------------------------------------------- |
| JS (reference) | ⬜ Not audited | Rounding applied server-side; client reads `odds_rounded` |
| TS             | ⬜ Partial     | Reads pre-rounded values; display formatting ✅ (HEDGE-86) |
| UMA            | ⬜ Not audited | Phase 5                                                   |

## Related Features

* F006 — Odds Calculation (`oddsActual` is the input to this algorithm)
* F007 — RTP Margin (margin applied before rounding)
* F024 — Odds Display (UI display of `oddsRounded`)
* F032 — RTP Config (operator enables/disables rounding at installation)
