Dec!() { /* proc-macro */ }
Expand description
Macro used to convert a number literal into a Decimal
.
The literal must be in the form [+|-]<int>[.<frac>][<e|E>[+|-]<exp>] or [+|-].<frac>[<e|E>[+|-]<exp>].
The resulting number of fractional digits is determined by the number of digits in the fractional part of the literal minus the value of the signed exponent.
The resulting value must not exceed the limits given by the internal
representaion of Decimal
:
- The coefficient must fit into an
i128
. - The number of fractional digits must not exceed the constant
MAX_N_FRAC_DIGITS
.
§Panics
The macro panics if the conditions listed above are not met!
§Examples
ⓘ
let d = Dec!(17.5);
assert_eq!(d.to_string(), "17.5");
let d = Dec!(-170.5e-2);
assert_eq!(d.to_string(), "-1.705");