Skip to content

Commit 8489c60

Browse files
committed
Multiply amounts with decs
1 parent a9868c4 commit 8489c60

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

crates/core/src/token.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ impl Amount {
287287
DenominatedAmount::from_str(string).map(|den| den.amount)
288288
}
289289

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+
290297
/// Multiply by a decimal [`Dec`] with the result rounded up. Returns an
291298
/// error if the dec is negative. Checks for overflow.
292299
pub fn mul_ceil(&self, dec: Dec) -> Result<Self, arith::Error> {

0 commit comments

Comments
 (0)