| Crates.io | percentum |
| lib.rs | percentum |
| version | 0.0.6 |
| created_at | 2025-02-28 21:53:54.016987+00 |
| updated_at | 2025-06-19 22:15:32.633233+00 |
| description | Percentage type sanity |
| homepage | |
| repository | https://github.com/clarkmoody/percentum |
| max_upload_size | |
| id | 1573231 |
| size | 37,106 |
per centum - "by a hundred"
A sane Percentage data type for Rust that encodes the underlying numeric representation explicitly.
let p = Percentage::from_fraction(0.55);
let q = Percentage::from_points(55.0);
assert_eq!(p, q);
decimal: Implementation for rust_decimal::Decimalserde: Modules for serde operations on percentage points or fractions#[derive(serde::Deserialize)]
struct Data {
#[serde(with = "serde_fraction")]
rate: Percentage<f64>,
}
let d = serde_json::from_str(r#"{ "rate": 0.55 }"#).unwrap();
assert_eq!(d.rate, Percentage::from_points(55.0));