fix: ignoring decimal place accidentally
This commit is contained in:
parent
c745d6b5d2
commit
098df2aef2
1 changed files with 15 additions and 10 deletions
|
|
@ -19,8 +19,11 @@ pub fn pretty_eval(mut input: String) -> Result<String, Error> {
|
|||
.is_some();
|
||||
|
||||
let result = nodes::eval(&input)?;
|
||||
let display_digits = if result >= 1000 || result < 1 {
|
||||
get_significant_digits(&result).min(MAX_DIGITS)
|
||||
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 {
|
||||
|
|
@ -28,7 +31,7 @@ pub fn pretty_eval(mut input: String) -> Result<String, Error> {
|
|||
// 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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue