fuzzy_fraction

Crates.iofuzzy_fraction
lib.rsfuzzy_fraction
version0.1.2
sourcesrc
created_at2021-11-30 14:16:14.939703
updated_at2023-07-17 15:21:31.33756
descriptionStruct for approximated human-readable fraction representation..
homepage
repositoryhttps://github.com/p4ymak/fuzzy_fraction
max_upload_size
id489803
size11,538
Roman Chumak (p4ymak)

documentation

README

Rust struct for approximated human-readable fraction representation.. No GCD or any dependencies involved..

use fuzzy_fraction::FuzzyFraction;

assert_eq!(FuzzyFraction::from_float(0.5).to_string(), "1/2");
assert_eq!(FuzzyFraction::from_float(-1.33).to_string(), "-1 1/3");

assert_eq!(FuzzyFraction::from_ints(1920, 1080).to_string(), "1 7/9");
assert_eq!(FuzzyFraction::from_ints(-10, 31).to_string(), "-1/3");

let ff = FuzzyFraction::from_ints(-1920, 1080);
assert_eq!(ff.to_string(), "-1 7/9");
assert_eq!(ff.ratio_fmt(), "16:9");
Commit count: 6

cargo fmt