Expand description
A helpful macro for instantiating Decimal
numbers.
By default, this requires rust_decimal
to be available at the project root. e.g. the macro
will effectively produce:
ⓘ
::rust_decimal::Decimal::from_parts(12345, 0, 0, false, 4)
While this is convenient for most use cases, it is sometimes not desired behavior when looking
to reexport the library. Consequently, this behavior can be modified by enabling the feature
reexportable
. When this feature is enabled, the macro will instead reproduce the functional
equivalent of:
ⓘ
Decimal::from_parts(12345, 0, 0, false, 4)
§Examples
use rust_decimal_macros::dec;
// If the reexportable feature is enabled, `Decimal` needs to be in scope
#[cfg(feature = "reexportable")]
use rust_decimal::Decimal;
let number = dec!(1.2345);
assert_eq!("1.2345", number.to_string());
let number = dec!(-5.4321);
assert_eq!("-5.4321", number.to_string());
Macros§
- Convenience function for creating decimal numbers