2 releases
0.1.1 | Apr 10, 2024 |
---|---|
0.1.0 | Apr 10, 2024 |
#225 in Value formatting
19KB
379 lines
This crate formats numbers using metric prefixes:
assert_eq!(123456.si_format().to_string(),"123k");
This provides more limited functionality than si-scale, but works without std, alloc, and (optionally) floating point arithmetic. This is primarily intended to make numbers in logs and debug printing more readable at a minimum runtime cost.
lib.rs
:
This crate formats numbers using metric prefixes:
assert_eq!(123456.si_format().to_string(),"123k")
You may specify a shift by a certain number of decimal places. This is particularly useful for integers that represent a fixed point fraction:
let d = Duration::from_micros(20);
assert_eq!(format!("{}s",d.as_nanos().si_format().with_shift(-9)),"20.0µs");
Rounding
Currently, the method used for rounding is unspecified. 0.5
may be rounded either up or down.
No-std
This crate fully supports no-std and environments without support for floating point numbers.
Floating point
Formatting of floating point numbers is optionally available via the float*
features.
These enable fromatting of floating point numbers up to the specific width (32 or 64 bit).
In addition, either std
or libm
need to be enabled for implementations of some required floating point functions.
Dependencies
~98KB