Skip to main content

round

Function round 

Source
pub fn round(n: f64, precision: Option<i32>) -> Result<JValue, FunctionError>
Expand description

$round(number, precision) - Round to precision using “round half to even” (banker’s rounding)

This implements the same rounding behavior as JSONata’s JavaScript implementation, which rounds .5 values to the nearest even number.

precision can be:

  • positive: round to that many decimal places (e.g., 2 -> 0.01)
  • zero or omitted: round to nearest integer
  • negative: round to powers of 10 (e.g., -2 -> nearest 100)