mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-26 00:05:57 +01:00
Merge pull request #856 from davidcaseria/amount-convert-unit
Add Amount::convert_unit convenience method
This commit is contained in:
@@ -172,6 +172,15 @@ impl Amount {
|
||||
acc.checked_add(x).ok_or(Error::AmountOverflow)
|
||||
})
|
||||
}
|
||||
|
||||
/// Convert unit
|
||||
pub fn convert_unit(
|
||||
&self,
|
||||
current_unit: &CurrencyUnit,
|
||||
target_unit: &CurrencyUnit,
|
||||
) -> Result<Amount, Error> {
|
||||
to_unit(self.0, current_unit, target_unit)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Amount {
|
||||
|
||||
Reference in New Issue
Block a user