Skip to main content

round

Function round 

Source
pub fn round(
    value: Value,
    precision: Option<i32>,
    method: Option<&str>,
    kwargs: Kwargs,
) -> Result<Value, Error>
Expand description

Round the number to a given precision.

The first parameter specifies the precision (default is 0), the second the rounding method:

  • common rounds half to even (default)
  • ceil always rounds up
  • floor always rounds down

Both can also be passed as keyword arguments. Integers are returned unchanged unless the precision is negative.

{{ 42.55|round }}
  -> 43.0
{{ 42.55|round(1, "floor") }}
  -> 42.5
{{ 42.15|round(method="ceil") }}
  -> 43.0
{{ 1234|round(-2) }}
  -> 1200