pub fn decimal_to_parts(value: Decimal) -> Result<(i64, i32), MoneyError>Expand description
Splits a number into (units, nano). Both parts get the sign of the value.
§Errors
MoneyError::TooManyDecimals if the value does not fit into billionths without rounding,
MoneyError::OutOfRange if the integer part does not fit in an i64.
§Examples
use rust_decimal::Decimal;
use brokapi_tbank_protocol::money::decimal_to_parts;
assert_eq!(decimal_to_parts(Decimal::new(11425, 2))?, (114, 250_000_000));
assert_eq!(decimal_to_parts(Decimal::new(-1, 2))?, (0, -10_000_000));
// Trailing zeros are not decimals: 0.5000000000 has one.
assert_eq!(decimal_to_parts(Decimal::new(5_000_000_000, 10))?, (0, 500_000_000));