(s: &mut String, val: f64, decimals: u32)
| 104 | clippy::cast_precision_loss |
| 105 | )] |
| 106 | fn write_float(s: &mut String, val: f64, decimals: u32) { |
| 107 | // Handle integer part |
| 108 | let int_part = val as u64; |
| 109 | write_u64(s, int_part); |
| 110 | |
| 111 | if decimals > 0 { |
| 112 | s.push('.'); |
| 113 | |
| 114 | // Calculate fractional part |
| 115 | let mut frac = val - int_part as f64; |
| 116 | for _ in 0..decimals { |
| 117 | frac *= 10.0; |
| 118 | let digit = frac as u8; |
| 119 | s.push((b'0' + digit) as char); |
| 120 | frac -= f64::from(digit); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /// Round an f64 to nearest integer (`f64::round` is not in core) |
| 126 | #[allow( |
no test coverage detected