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 result = nodes::eval(&input)?;
|
||||
let display_digits =
|
||||
get_significant_digits(&result)
|
||||
.min(max_digits)
|
||||
.max(if result >= 1000 || result < 1 {
|
||||
let display_digits = get_significant_digits(&result).clamp(
|
||||
if result >= 1000 || result < 1 {
|
||||
1
|
||||
} else if result >= 100 {
|
||||
3
|
||||
|
|
@ -23,7 +21,9 @@ pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> {
|
|||
// if result >= 1
|
||||
} else {
|
||||
1
|
||||
});
|
||||
},
|
||||
max_digits,
|
||||
);
|
||||
|
||||
Ok(format!(
|
||||
"{prefix}{deliminator}{result:.display_digits$}{}",
|
||||
|
|
|
|||
Loading…
Reference in a new issue