Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

rounding

Rounding & Precision Utilities

Various rounding modes and precision control for DeFi applications.

Rounding Modes

  • round_down / round_up - Floor/Ceiling
  • round_half_up - Standard rounding (0.5 rounds up)
  • round_toward_zero - Truncation
  • round_away_from_zero - Round away from zero

Precision Control

  • truncate_decimals - Truncate to N decimal places
  • round_to_decimals - Round to N decimal places

Comparison & Clamping

  • approx_equal - Check equality within tolerance
  • clamp - Constrain value to range
  • min / max - Minimum/Maximum

Fully qualified path: cairo_fp::f128::math::rounding

Free functions

round_downRounds down to the nearest integer (floor).
round_upRounds up to the nearest integer (ceiling).
round_half_upStandard rounding (half up). Rounds to nearest integer, with 0.5 rounding up.
round_toward_zeroRounds toward zero (truncation)….
round_away_from_zeroRounds away from zero….
truncate_decimals
round_to_decimals
approx_equal
clamp
min
max
_split_unsigned