Crate si_format

source ·
Expand description

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.

Structs§

  • This is a number wrapped for formatting. The with_* methods can be used to customize display.

Traits§

  • A Type that can be formatted with a SiFormat.