Crates.io | float-format |
lib.rs | float-format |
version | 0.1.3 |
source | src |
created_at | 2022-06-02 08:07:33.967748 |
updated_at | 2022-06-08 16:32:43.217691 |
description | A library for custom floating point number format |
homepage | |
repository | https://github.com/LioQing/float-format |
max_upload_size | |
id | 598726 |
size | 39,984 |
This is a crate for customizing the format of floating point numbers. This crate is still work in progress, many features are still to be added.
So far everything is unstable.
use float_format::*;
fn main() {
// Create with a custom format and parse from a string.
let float = Float::from_str(
Format::new_ieee_excess(16, 64),
"123456.789012345",
).unwrap();
// Format the float with custom precision.
assert_eq!(format!("{:.8}", float), "123456.78901234");
// Convert from primitive float types.
assert_eq!(Float::from(0.2f32).to_f32(), 0.2f32);
assert_eq!(Float::from(0.2f64).to_f64(), 0.2f64);
}