#numbers #formatting #human #filesize #magnitude

no-std human_format

Rust版本的human-format,从node迁移而来,为我们格式化数字,而机器仍在岸边

5个稳定版本

使用旧的Rust 2015

1.1.0 2024年2月17日
1.0.3 2019年11月24日
1.0.2 2018年2月2日
1.0.1 2018年1月29日

值格式化中排名第28

Download history 10249/week @ 2024-04-27 10674/week @ 2024-05-04 12801/week @ 2024-05-11 14145/week @ 2024-05-18 12114/week @ 2024-05-25 14347/week @ 2024-06-01 13487/week @ 2024-06-08 13923/week @ 2024-06-15 14392/week @ 2024-06-22 14157/week @ 2024-06-29 12915/week @ 2024-07-06 12718/week @ 2024-07-13 13553/week @ 2024-07-20 14550/week @ 2024-07-27 14582/week @ 2024-08-03 12436/week @ 2024-08-10

每月下载量56,680
45crates使用(直接使用17个)

MIT许可证

14KB
197

human-format-rs

Crates.io Documentation

Rust版本的human-format,从node迁移而来,为我们格式化数字,而机器仍在岸边。

主分支 开发分支
Master Develop

什么是human_format?

该crate的主要目的是基于量级以可定制的方式格式化数字。它受到了human-format包的启发,并希望最终提供一个惯用的Rust移植版本。

用法

  1. 将此包作为依赖项添加
[dependencies]
human_format = "1.0"
  1. 打印一些人类可读的字符串

示例

// 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()
    .with_decimals(1)
    .with_separator("")
    .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 custom_binary_scales = Scales::new();

custom_binary_scales
    .with_base(1000)
    .with_suffixes(["".to_owned(),"k".to_owned(), "M".to_owned(), "G".to_owned(), "T".to_owned(), "P".to_owned(), "E".to_owned(), "Z".to_owned(), "Y".to_owned()].to_vec());

// 1.00 kB
Formatter::new()
    .with_scales(custom_binary_scales)
    .with_units("B")
    .format(1000 as f64);

// 1.00 kiB
Formatter::new()
    .with_scales(Scales::Binary())
    .with_units("B")
    .format(1000 as f64);

更多示例请参阅tests/demo.rs

无运行时依赖