Fix numbers unnecessarily displayed in E notation
This commit is contained in:
parent
71548793c5
commit
e4fc479091
@ -164,6 +164,9 @@ match string {
|
||||
|
||||
### Potential Improvements
|
||||
- Support for conversion between Power, Current, Resistance and Voltage. Multiplication and division is currently supported, but not conversions using sqrt or pow.
|
||||
- Move to pure-rust decimal implementation
|
||||
- `rust_decimal`: Only supports numbers up to ~1E+29
|
||||
- `bigdecimal`: Lacking math functions
|
||||
- E notation, like 2E+10
|
||||
- Unit types
|
||||
- Currency: How to go about dynamically updating the weights?
|
||||
|
||||
12
src/lib.rs
12
src/lib.rs
@ -22,6 +22,7 @@
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
use std::fmt::{self, Display};
|
||||
use std::time::{Instant};
|
||||
use decimal::d128;
|
||||
use crate::units::Unit;
|
||||
@ -65,6 +66,17 @@ impl Number {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Display for Number {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// 0.2/0.01 results in 2E+1, but if we add zero it becomes 20
|
||||
let fixed_value = self.value + d128!(0);
|
||||
let output = match self.unit {
|
||||
Unit::NoUnit => format!("{}", fixed_value),
|
||||
unit => format!("{} {:?}", fixed_value, unit),
|
||||
};
|
||||
return write!(f, "{}", output);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
/// Math operators like [`Multiply`](Operator::Multiply), parentheses, etc.
|
||||
|
||||
@ -14,7 +14,7 @@ fn main() {
|
||||
match eval(&args[1], true, Unit::Celsius, verbose) {
|
||||
Ok(answer) => {
|
||||
if !verbose {
|
||||
println!("{} {:?}", answer.value, answer.unit)
|
||||
println!("{}", answer);
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user