refactor: simplify min and max digits
min and max methods are pretty confusing, this is much nicer.
This commit is contained in:
parent
6980655714
commit
56d5f7bd06
1 changed files with 13 additions and 13 deletions
|
|
@ -11,10 +11,8 @@ pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> {
|
||||||
let should_add_back_backslash = input.contains('\\');
|
let should_add_back_backslash = input.contains('\\');
|
||||||
|
|
||||||
let result = nodes::eval(&input)?;
|
let result = nodes::eval(&input)?;
|
||||||
let display_digits =
|
let display_digits = get_significant_digits(&result).clamp(
|
||||||
get_significant_digits(&result)
|
if result >= 1000 || result < 1 {
|
||||||
.min(max_digits)
|
|
||||||
.max(if result >= 1000 || result < 1 {
|
|
||||||
1
|
1
|
||||||
} else if result >= 100 {
|
} else if result >= 100 {
|
||||||
3
|
3
|
||||||
|
|
@ -23,7 +21,9 @@ pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> {
|
||||||
// if result >= 1
|
// if result >= 1
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
});
|
},
|
||||||
|
max_digits,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
"{prefix}{deliminator}{result:.display_digits$}{}",
|
"{prefix}{deliminator}{result:.display_digits$}{}",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue