#float #numbers #format #layout #custom

float-format

A library for custom floating point number format

4 releases

0.1.3 Jun 8, 2022
0.1.2 Jun 4, 2022
0.1.1 Jun 4, 2022
0.1.0 Jun 2, 2022

#18 in #custom

MIT license

33KB
637 lines

Float Format

crates.io downloads docs build size license

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);
}

Dependencies

~3.5MB
~85K SLoC