From 8ffea918c4f928d03032769db2493ac9be1f4543 Mon Sep 17 00:00:00 2001 From: Fabian Schmidt Date: Mon, 5 Aug 2024 12:52:57 +0200 Subject: [PATCH] either it's slightly faster or it's a measurement error --- src/main/rust/src/models/station_measurements.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/rust/src/models/station_measurements.rs b/src/main/rust/src/models/station_measurements.rs index 5c89597..7312ccd 100644 --- a/src/main/rust/src/models/station_measurements.rs +++ b/src/main/rust/src/models/station_measurements.rs @@ -26,9 +26,12 @@ impl StationMeasurements { impl Display for StationMeasurements { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let min = self.min as f64 / 10.0; - let max = self.max as f64 / 10.0; + let min_pre = self.min / 10; + let min_suf = (self.min % 10).abs(); + let max_pre = self.max / 10; + let max_suf = (self.max % 10).abs(); + // casting here is faster let avg = (self.sum as f64 / self.count as f64) / 10.0; - write!(f, "{min}/{avg:.1}/{max}") + write!(f, "{min_pre}.{min_suf}/{avg:.1}/{max_pre}.{max_suf}") } }