Skip to content

clarkmoody/percentum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Percentum

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);

Feature Flags

  • decimal: Implementation for rust_decimal::Decimal
  • serde: 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));

About

Sane Percentage data type for Rust

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages