From 098df2aef2b7100bae6277f763588a439ce4fb93 Mon Sep 17 00:00:00 2001 From: electria Date: Fri, 2 Oct 2026 13:32:53 -0700 Subject: [PATCH] fix: ignoring decimal place accidentally --- src/formatting.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index cf3f6e5..b157564 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -19,16 +19,19 @@ pub fn pretty_eval(mut input: String) -> Result { .is_some(); let result = nodes::eval(&input)?; - let display_digits = if result >= 1000 || result < 1 { - get_significant_digits(&result).min(MAX_DIGITS) - } else if result >= 100 { - 3 - } else if result >= 10 { - 2 - // if result >= 1 - } else { - 1 - }; + let display_digits = + get_significant_digits(&result) + .min(MAX_DIGITS) + .max(if result >= 1000 || result < 1 { + 1 + } else if result >= 100 { + 3 + } else if result >= 10 { + 2 + // if result >= 1 + } else { + 1 + }); Ok(format!( "{}{}{result:.display_digits$}{}", @@ -60,6 +63,8 @@ fn test_basic_up_to_999() { assert_eq!(pretty_eval("100".into()).unwrap(), "100"); assert_eq!(pretty_eval("999".into()).unwrap(), "999"); assert_eq!(pretty_eval("1000".into()).unwrap(), "1 * 10^3"); + + assert_eq!(pretty_eval("11.111111".into()).unwrap(), "11.111111"); } pub fn get_significant_digits(n: &Float) -> usize {