> ## Documentation Index
> Fetch the complete documentation index at: https://docs.clevis.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Rounding

> How monetary values are rounded

All monetary calculations use `Decimal` arithmetic (never floating-point) to ensure exact results.

## Default behavior

Values are rounded using **HALF\_UP** strategy to **2 decimal places** by default.

Each value is rounded **once** — at the end of its computation. Intermediate calculations carry full 28-digit precision to prevent rounding error accumulation.

```
Intermediate:  839.4400000000000000000000000000
Final:         839.44
```

## Overriding precision

You can override the number of decimal places per request:

```json theme={null}
{
  "options": {
    "precision": 4
  }
}
```

Valid range: `0` to `6` decimal places.

## Rounding strategies

The engine supports multiple rounding strategies (configured per scheme in the DSL):

| Strategy    | Behavior                                       | Example (2.545 to 2dp) |
| ----------- | ---------------------------------------------- | ---------------------- |
| `HALF_UP`   | Round half away from zero                      | 2.55                   |
| `HALF_EVEN` | Round half to nearest even (banker's rounding) | 2.54                   |
| `FLOOR`     | Always round down                              | 2.54                   |
| `CEILING`   | Always round up                                | 2.55                   |

Most Latin American tax authorities expect `HALF_UP`, which is the default for all current schemes.

## Why strings, not numbers

All monetary values in API responses are serialized as **JSON strings**:

```json theme={null}
{
  "net_salary": "20039.25",
  "total_deductions": "3960.75"
}
```

JSON numbers are IEEE 754 floats, which cannot represent all decimal values exactly. For example, `0.1 + 0.2 = 0.30000000000000004` in most languages. Returning strings ensures the exact computed value reaches your application without precision loss.

Parse response values with your language's decimal type:

<CodeGroup>
  ```python Python theme={null}
  from decimal import Decimal

  net = Decimal(result["summary"]["net_salary"])  # Exact
  ```

  ```javascript Node.js theme={null}
  // Use a decimal library like decimal.js
  import Decimal from "decimal.js";

  const net = new Decimal(result.summary.net_salary); // Exact
  ```
</CodeGroup>
