1 unstable release

0.1.0 Sep 12, 2019

#2625 in Rust patterns

Download history 55839/week @ 2025-09-21 55913/week @ 2025-09-28 52049/week @ 2025-10-05 60713/week @ 2025-10-12 63638/week @ 2025-10-19 64845/week @ 2025-10-26 66840/week @ 2025-11-02 61204/week @ 2025-11-09 67115/week @ 2025-11-16 62602/week @ 2025-11-23 72325/week @ 2025-11-30 65656/week @ 2025-12-07 78793/week @ 2025-12-14 42582/week @ 2025-12-21 30902/week @ 2025-12-28 68160/week @ 2026-01-04

225,014 downloads per month
Used in 979 crates (23 directly)

MIT/Apache

9KB
129 lines

Percentage

percentage is a crate trying to make using percentages in a safer way and easier to debug. Whenever you see a Percentage, you will know what is being calculated, instead of having to revise the code.

Example

// You only need to import the `Percentage` struct
use percentage::Percentage;

// Here we create the percentage to apply
let percent = Percentage::from(50);

println!("{}", percent.value()); // Will print '50'

// We can apply the percent to any number we want
assert_eq!(15, percent.apply_to(30));
println!("50% of 30 is: {}", percent.apply_to(30)); // Will print '50% of 30 is: 15'

// If you need to use floating points for the percent, you can use `from_decimal` instead

let percent = Percentage::from_decimal(0.5);
assert_eq!(15.0, percent.apply_to(30.0));
println!("50% of 30.0 is: {}", percent.apply_to(30.0)); // Will print '50% of 30.0 is: 15.0'

Dependencies

~465KB