Fixed quantity printing

pull/2/head
Mark 2023-04-01 18:26:30 -07:00
parent bb200548f1
commit cb227d9539
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
2 changed files with 5 additions and 4 deletions

View File

@ -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
const PRINT_LEN: usize = 5; // How many significant digits we will show in output

View File

@ -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