fix: ignoring decimal place accidentally
This commit is contained in:
parent
c745d6b5d2
commit
098df2aef2
1 changed files with 15 additions and 10 deletions
|
|
@ -19,16 +19,19 @@ pub fn pretty_eval(mut input: String) -> Result<String, Error> {
|
||||||
.is_some();
|
.is_some();
|
||||||
|
|
||||||
let result = nodes::eval(&input)?;
|
let result = nodes::eval(&input)?;
|
||||||
let display_digits = if result >= 1000 || result < 1 {
|
let display_digits =
|
||||||
get_significant_digits(&result).min(MAX_DIGITS)
|
get_significant_digits(&result)
|
||||||
} else if result >= 100 {
|
.min(MAX_DIGITS)
|
||||||
3
|
.max(if result >= 1000 || result < 1 {
|
||||||
} else if result >= 10 {
|
1
|
||||||
2
|
} else if result >= 100 {
|
||||||
// if result >= 1
|
3
|
||||||
} else {
|
} else if result >= 10 {
|
||||||
1
|
2
|
||||||
};
|
// if result >= 1
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
});
|
||||||
|
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
"{}{}{result:.display_digits$}{}",
|
"{}{}{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("100".into()).unwrap(), "100");
|
||||||
assert_eq!(pretty_eval("999".into()).unwrap(), "999");
|
assert_eq!(pretty_eval("999".into()).unwrap(), "999");
|
||||||
assert_eq!(pretty_eval("1000".into()).unwrap(), "1 * 10^3");
|
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 {
|
pub fn get_significant_digits(n: &Float) -> usize {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue