Skip to main content

Crate amount

Crate amount 

Source
Expand description

The one amount grammar of the transaction forms.

An amount is a decimal (10.5, -3, +.25) or an exact fraction a/b (optional sign on a, positive integer b). It parses into a reduced (numerator, denominator) pair of i64, with no floating point.

Enums§

AmountError

Functions§

display
Display text of num/denom: the exact decimal or fraction, falling back to the wire token (n/0 for a zero denominator).
format_amount
Renders num/denom so the amount parser reads back the same reduced value: the exact decimal when it terminates and the parser accepts it, otherwise the reduced fraction a/b. Never rounds. None for a zero denominator or a value the parser cannot hold.
parse_amount
Parses an amount into a reduced (numerator, denominator); the denominator is positive and the numerator is never i64::MIN.
reduce_to_i64
Reduces num/denom by their gcd and narrows it to i64; denom must be positive. Fails with Overflow when either part does not fit, or the numerator is i64::MIN.
wire_rational
Wire token of a Rational64; a zero-denominator ratio (constructible only unchecked) renders as n/0, which the reader rejects instead of misreading.
wire_token
Wire token for the nomiscript reader: the reduced n for a whole value, else n/d with the sign on n. None for a zero denominator.