pub struct Micros(pub i64);Expand description
Exact decimal stored as an integer count of millionths (10^-6).
CSV amounts and quantities are parsed from decimal text. Nothing in this type uses floating point. Half-up rounding happens only in the display helpers.
Tuple Fields§
§0: i64Implementations§
Source§impl Micros
impl Micros
pub const ZERO: Self
Sourcepub fn parse(raw: &str) -> Result<Self, DecimalError>
pub fn parse(raw: &str) -> Result<Self, DecimalError>
Parse [-+]digits[.digits][e[-+]digits].
A value that is not an exact multiple of 10^-6 is TooManyDecimals.
Trailing zeros are kept only when the value still fits in 6 decimal places
(1.2300000 is 1.23; 1.2345678 is rejected).
Sourcepub fn to_decimal_string(self) -> String
pub fn to_decimal_string(self) -> String
44.232000. Always 6 digits after the decimal point.
Sourcepub fn format_cents(self) -> String
pub fn format_cents(self) -> String
Half-up, away from zero, to cents. Display only.
Sourcepub fn format_quantity(self) -> String
pub fn format_quantity(self) -> String
Up to 3 decimal places, half-up, trailing zeros removed. Used for minutes.
Sourcepub fn whole_units(self) -> Option<i64>
pub fn whole_units(self) -> Option<i64>
Whole units when this value has no fractional millionths.
Sourcepub fn checked_add(self, rhs: Self) -> Option<Self>
pub fn checked_add(self, rhs: Self) -> Option<Self>
None when the sum does not fit in i64 micros, instead of panicking.
Use this to add amounts from untrusted input, such as CSV rows.
Micros deliberately has no Add, AddAssign or Sum impl: every sum
must choose between this checked form and an explicit saturating one,
so no + on money can panic on overflow.