diff --git a/src/main.rs b/src/main.rs index ff8bb70..84c33ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,17 +34,31 @@ pub fn parse_and_calc_humanreadable(mut input: String) -> String { false }; + // no need to remove the character here, + // as we ignore the ampersand in all other logic already + let should_add_back_alignment = input.contains('&'); + let result = parse_and_calc(&input); format!( "{0}{result:.1$}", - if should_add_back_equals { "= " } else { "" }, + if should_add_back_equals && should_add_back_alignment { + "& = " + } else if should_add_back_equals { + "= " + } else if should_add_back_alignment { + "& " + } else { + "" + }, get_significant_digits(&result), ) } #[test] fn test_equals_readdition() { assert_eq!(parse_and_calc_humanreadable(" = 11".into()), "= 11"); + assert_eq!(parse_and_calc_humanreadable(" &= 11".into()), "& = 11"); + assert_eq!(parse_and_calc_humanreadable(" & 11".into()), "& 11"); } pub fn parse_and_calc(s: &str) -> Float {