We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a9868c4 commit 8489c60Copy full SHA for 8489c60
crates/core/src/token.rs
@@ -287,6 +287,13 @@ impl Amount {
287
DenominatedAmount::from_str(string).map(|den| den.amount)
288
}
289
290
+ /// Multiply by a decimal, with the result rounded down.
291
+ pub fn checked_mul_dec(&self, dec: Dec) -> Option<Amount> {
292
+ self.raw
293
+ .checked_mul_div(dec.abs(), Uint::exp10(POS_DECIMAL_PRECISION as _))
294
+ .map(|(result, _)| result.into())
295
+ }
296
+
297
/// Multiply by a decimal [`Dec`] with the result rounded up. Returns an
298
/// error if the dec is negative. Checks for overflow.
299
pub fn mul_ceil(&self, dec: Dec) -> Result<Self, arith::Error> {
0 commit comments