From cb227d95395a82488c197353112e85ed87a0730f Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 1 Apr 2023 18:26:30 -0700 Subject: [PATCH] Fixed quantity printing --- src/quantity/mod.rs | 2 +- src/quantity/quantity.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/quantity/mod.rs b/src/quantity/mod.rs index c70fc59..f8c3f77 100644 --- a/src/quantity/mod.rs +++ b/src/quantity/mod.rs @@ -4,4 +4,4 @@ pub mod quantity; pub use crate::quantity::quantity::Quantity; const FLOAT_PRECISION: u32 = 2048; -const PRINT_LEN: usize = 4; // How many significant digits we will show in output \ No newline at end of file +const PRINT_LEN: usize = 5; // How many significant digits we will show in output \ No newline at end of file diff --git a/src/quantity/quantity.rs b/src/quantity/quantity.rs index 31052f3..c56be24 100644 --- a/src/quantity/quantity.rs +++ b/src/quantity/quantity.rs @@ -48,15 +48,16 @@ impl ToString for Quantity{ exp_u = exp.try_into().unwrap() } - if exp_u >= 4 { + if exp_u >= PRINT_LEN { // Exponential notation let pre = &string[0..1]; let post = &string[1..]; format!( - "{pre}{}{post}e{}{exp}", + "{pre}{}{post}e{}", if post.len() != 0 {"."} else {""}, - if exp > 0 {"+"} else {""}, + //if exp > 0 {"+"} else {""}, + exp - 1 ) } else { if exp <= 0 { // Decimal, needs `0.` and leading zeros