From 1c2b18c86708f177177531d182349d2f7605c3cc Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Wed, 14 Dec 2022 11:14:27 +0100 Subject: [PATCH] Time formatting. Display more digits when formatting time in ms and s --- src/day14.rs | 9 +++++++-- src/main.rs | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/day14.rs b/src/day14.rs index f732d8a..3f48e1f 100644 --- a/src/day14.rs +++ b/src/day14.rs @@ -10,7 +10,9 @@ pub struct Rocks { impl Rocks { fn new() -> Self { - Rocks { state: Box::new([false; N * M]) } + Rocks { + state: Box::new([false; N * M]), + } } fn get(&self, i: usize, j: usize) -> bool { @@ -30,7 +32,10 @@ pub fn parse(input: &str) -> (Rocks, usize) { .split("->") .map(|p| { let ji: Vec<&str> = p.split(',').collect(); - (ji[1].parse::().unwrap(), ji[0].parse::().unwrap()) + ( + ji[1].parse::().unwrap(), + ji[0].parse::().unwrap(), + ) }) .tuple_windows() { diff --git a/src/main.rs b/src/main.rs index 557f3b1..1229242 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,8 +93,8 @@ fn format_micros(t: u128) -> String { if t < 10_000 { format!("{} μs", t) } else if t < 10_000_000u128 { - format!("{} ms", t / 1_000u128) + format!("{:.2} ms", t as f64 / 1e3f64) } else { - format!("{} s", t / 1_000_000u128) + format!("{:.2} s", t as f64 / 1e6f64) } } -- 2.45.2