blob: 0d9090bcc8a5a1283c8e71ded17192952ccd11af (
plain)
1
2
3
4
5
6
|
pub fn round(v: f64, precision: i64) -> f64 {
// PHP's default mode is PHP_ROUND_HALF_UP (round half away from zero),
// which matches Rust's f64::round.
let factor = 10f64.powi(precision as i32);
(v * factor).round() / factor
}
|