Skip to main content

parts_to_decimal

Function parts_to_decimal 

Source
pub fn parts_to_decimal(units: i64, nano: i32) -> Decimal
Expand description

Converts raw units and nano to a [Decimal], exactly.

nano is in billionths and should carry the same sign as units (or be the only non-zero part). The function does not check the range of nano: it is simply added.

§Examples

use rust_decimal::Decimal;
use brokapi_tbank_protocol::money::parts_to_decimal;

assert_eq!(parts_to_decimal(1, 500_000_000), Decimal::new(15, 1));
assert_eq!(parts_to_decimal(-1, -500_000_000), Decimal::new(-15, 1));