Crates.io | probability_to_friendly_string |
lib.rs | probability_to_friendly_string |
version | 0.3.0 |
source | src |
created_at | 2019-11-06 03:47:31.149569 |
updated_at | 2020-11-10 03:07:17.868706 |
description | Make probabilities more intuitive by converting them to odds. (i.e. 72.3% becomes "5 in 7") |
homepage | https://github.com/gregstoll/probabilityToFriendlyString |
repository | |
max_upload_size | |
id | 178507 |
size | 14,157 |
Published as probability_to_friendly_string crate.
Requires Ruby 2018 edition
Usage:
use probability_to_friendly_string::FriendlyProbability;
let friendly = FriendlyProbability::from_probability(0.723);
assert_eq!(5, friendly.numerator());
assert_eq!(7, friendly.denominator());
assert_eq!("Good chance", friendly.friendly_description());
assert_eq!("5 in 7", friendly.friendly_string());
let friendly = FriendlyProbability::from_probability(0.999);
assert_eq!(">99 in 100", friendly.friendly_string());
let friendly = FriendlyProbability::from_probability(0.001);
assert_eq!("<1 in 100", friendly.friendly_string());
Note that passing a value less than 0.0 or greater than 1.0 to FriendlyProbability::from_probability
will panic.