parent
3f528ab183
commit
b0c2fe8f03
1 changed files with 8 additions and 12 deletions
|
@ -389,6 +389,14 @@ impl Number {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn fixed(self, precision: usize) -> Number {
|
||||||
|
match self {
|
||||||
|
Number::Int(v) => format!("{:.1$}", v, precision).into(),
|
||||||
|
Number::Float(v) => format!("{:.1$}", v, precision).into(),
|
||||||
|
Number::Decimal(v) => format!("{:.1$}", v, precision).into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn sqrt(self) -> Self {
|
pub fn sqrt(self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
Number::Int(v) => (v as f64).sqrt().into(),
|
Number::Int(v) => (v as f64).sqrt().into(),
|
||||||
|
@ -411,18 +419,6 @@ impl Number {
|
||||||
(v, p) => Number::Float(v.as_float().pow(p.as_float())),
|
(v, p) => Number::Float(v.as_float().pow(p.as_float())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------
|
|
||||||
//
|
|
||||||
// -----------------------------------
|
|
||||||
|
|
||||||
pub fn fixed(self, precision: usize) -> Number {
|
|
||||||
match self {
|
|
||||||
Number::Int(v) => format!("{:.1$}", v, precision).into(),
|
|
||||||
Number::Float(v) => format!("{:.1$}", v, precision).into(),
|
|
||||||
Number::Decimal(v) => v.round(precision as i64).into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for Number {}
|
impl Eq for Number {}
|
||||||
|
|
Loading…
Reference in a new issue