From 9cc6d7ea1f78844ddea6395645384653bfefef54 Mon Sep 17 00:00:00 2001 From: yuni Date: Thu, 28 Nov 2024 02:03:24 +0100 Subject: [PATCH] fix formatting of SI prefixes, add some new ones --- src/nature.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/nature.rs b/src/nature.rs index f3f4b83..dfd77d1 100644 --- a/src/nature.rs +++ b/src/nature.rs @@ -157,16 +157,24 @@ pub fn readable_speed(speed: f64) -> String { pub fn readable_si(value: f64) -> String { let abs = value.abs(); - if abs > 1e10 { + if abs > 1e13 { + return format!("{:.1} T", value / 1e9); + } else if abs > 1e10 { return format!("{:.1} G", value / 1e9); } else if abs > 1e7 { return format!("{:.1} M", value / 1e6); } else if abs > 1e4 { return format!("{:.1} k", value / 1e3); - } else if abs < 1e-2 { + } else if abs < 1e-15 { + return format!("{:.1} f", value * 1e15); + } else if abs < 1e-12 { + return format!("{:.1} p", value * 1e12); + } else if abs < 1e-7 { + return format!("{:.1} n", value * 1e9); + } else if abs < 1e-4 { + return format!("{:.1} µ", value * 1e6); + } else if abs < 1e-1 { return format!("{:.1} m", value * 1e3); - } else if abs < 1e-5 { - return format!("{:.1} µ", value * 1e3); } return format!("{:.1} ", value); }