#calculate #percent #percentages

percentage

一个用于计算百分比的库

1 个不稳定版本

0.1.0 2019年9月12日

9#percent 中排名

Download history 45291/week @ 2024-04-06 30500/week @ 2024-04-13 26981/week @ 2024-04-20 25058/week @ 2024-04-27 24188/week @ 2024-05-04 24575/week @ 2024-05-11 18215/week @ 2024-05-18 21304/week @ 2024-05-25 25598/week @ 2024-06-01 26578/week @ 2024-06-08 24197/week @ 2024-06-15 26453/week @ 2024-06-22 23249/week @ 2024-06-29 26029/week @ 2024-07-06 23015/week @ 2024-07-13 22761/week @ 2024-07-20

98,662 每月下载量
用于 533 库(其中 12 个直接使用)

MIT/Apache

9KB
129

Percentage

percentage 是一个库,旨在以更安全和更易于调试的方式使用百分比。每当您看到百分比时,您就会知道正在计算什么,而无需修改代码。

示例

// 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'

依赖项

~475KB