Round a floating-point value to the given number of decimal places using HALF_UP rounding mode (ties round away from zero). This matches Spark's `RoundBase` behaviour for `FloatType` / `DoubleType`, which internally converts the value to `BigDecimal` and rounds with `RoundingMode.HALF_UP`. # Arguments `value` – the floating-point number to round `scale` – number of decimal places to keep. - `sca
(value: T, scale: i32)
| 187 | /// round_float(125.0, -1) → 130.0 |
| 188 | /// ``` |
| 189 | fn round_float<T: num_traits::Float>(value: T, scale: i32) -> T { |
| 190 | if scale >= 0 { |
| 191 | let factor = T::from(10.0f64.powi(scale)).unwrap_or_else(T::infinity); |
| 192 | if factor.is_infinite() { |
| 193 | // Very large positive scale — value is already precise enough, return as-is |
| 194 | return value; |
| 195 | } |
| 196 | (value * factor).round() / factor |
| 197 | } else { |
| 198 | let factor = T::from(10.0f64.powi(-scale)).unwrap_or_else(T::infinity); |
| 199 | if factor.is_infinite() { |
| 200 | // Very large negative scale — any finite value rounds to 0 |
| 201 | return T::zero(); |
| 202 | } |
| 203 | (value / factor).round() * factor |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | /// Round an integer value to the given scale using HALF_UP rounding mode. |
| 208 | /// |
no test coverage detected
searching dependent graphs…