Rust Port of human-format from node, formatting numbers for us, while the machines are still at bay.
| Branch | Linux/MacOS | Windows |
| :-- | :--: | :--: |
| Master | |
|
| Develop |
|
|
The primary purpose for this crate is to format numbers in a customizable fashion based around magnitudes. It is inspired by the human-format package and the hope is to ultimately provide an idiomatic rust port.
toml
[dependencies]
human_format = "0.2"
rust
extern crate human_format;
```rust // 1.00 k Formatter::new() .format(1000 as f64));
// 1.34 k Formatter::new() .with_decimals(2) .format(1337 as f64);
// 1.3 k Formatter::new() .with_decimals(1) .format(1337 as f64);
// 1.3B Formatter::new() .withdecimals(1) .withseparator("") .format(1337000000 as f64);
// 1.00 - k Formatter::new() .with_separator(" - ") .format(1000 as f64);
// Define your own scales as you see fit let mut custombinaryscales = Scales::new();
custombinaryscales .withbase(1000) .withsuffixes(["".toowned(),"k".toowned(), "M".toowned(), "G".toowned(), "T".toowned(), "P".toowned(), "E".toowned(), "Z".toowned(), "Y".toowned()].tovec());
// 1.00 kB Formatter::new() .withscales(custombinaryscales) .withunits("B") .format(1000 as f64);
// 1.00 kiB Formatter::new() .withscales(Scales::Binary()) .withunits("B") .format(1000 as f64); ```
For more examples please consult tests/demo.rs