typst_utils

Function round_with_precision

source
pub fn round_with_precision(value: f64, precision: u8) -> f64
Expand description

Returns value with n digits after floating point where n is precision. Standard rounding rules apply (if n+1th digit >= 5, round up).

If rounding the value will have no effect (e.g., it’s infinite or NaN), returns value unchanged.

§Examples

let rounded = round_with_precision(-0.56553, 2);
assert_eq!(-0.57, rounded);