Skip to main content

The Problem

Standard f64 floating-point causes rounding errors:
In trading systems, these errors compound over thousands of calculations:
  • Incorrect P&L
  • Failed reconciliation
  • Checksum mismatches
  • Audit failures

The Solution

Havklo uses rust_decimal throughout:
rust_decimal provides 96-bit decimal representation with up to 28 significant digits - the same precision as .NET’s decimal type.

Where It Matters

Every price and quantity in Havklo is Decimal:

Scientific Notation

Kraken sometimes sends very small numbers in scientific notation:
Havklo parses these correctly:

Performance

Decimal is slower than f64, but still fast:
A 5x slowdown on a 1ns operation is still only 5ns - orders of magnitude faster than network latency.

Best Practices

1

Use the dec! macro

2

Keep calculations in Decimal

3

Format for display, don't convert

Avoid to_f64() unless required by external APIs. Each conversion loses precision.