paft-decimal
Backend-agnostic decimal helpers for the paft ecosystem.
Decimalaliases the active backend:rust_decimal::Decimalby default, orbigdecimal::BigDecimalwith thebigdecimalfeature- Backend-stable helpers for plain decimal parsing, canonical rendering, rounding, checked arithmetic, and exact scaled-unit conversion
- Constrained decimal newtypes:
NonNegativeDecimal,PositiveDecimal, andRatio - Serde adapters for canonical decimal strings
Decimal128Mantissafor decimal128 mantissa encoding used by DataFrame integrations
Install
Use the facade crate when you only need the decimal types it re-exports:
[]
= "0.9.0"
Depend directly when you need helpers such as parse_decimal,
try_to_scaled_units, from_minor_units, or the serde adapters:
[]
= "0.9.0"
Alternate decimal backend:
[]
= { = "0.9.0", = ["bigdecimal"] }
Features
bigdecimal: switch the activeDecimaltype fromrust_decimal::Decimaltobigdecimal::BigDecimalfor arbitrary precision decimals
Quickstart
use ;
let value = parse_decimal.unwrap;
assert_eq!;
let rounded =
round_dp_with_strategy;
assert_eq!;
let size = new.unwrap;
assert_eq!;
let pct = new.unwrap;
assert_eq!;
assert!;
Serde Adapters
Use the serde helpers when a decimal-backed field must keep the same JSON wire format under both decimal backends:
use Decimal;
Links
- API docs: https://docs.rs/paft-decimal
- Workspace overview: https://github.com/paft-rs/paft/blob/main/README.md
- License: LICENSE