Crates.io | digit_group |
lib.rs | digit_group |
version | 0.1.0 |
source | src |
created_at | 2017-02-06 12:00:21.64459 |
updated_at | 2017-02-06 12:00:21.64459 |
description | Provides grouping (thousands separators) for numeric types. |
homepage | |
repository | https://github.com/jaysonWL/digit_group |
max_upload_size | |
id | 8410 |
size | 24,746 |
This is a small Rust crate that provides grouping (aka "thousands separators") for numeric types.
Cargo.toml
:
[dependencies]
digit_group = "0.1"
main.rs
:
extern crate digit_group;
use digit_group{FormatGroup,custom_group};
fn main() {
let x: f64 = 12345678.112233;
// Typical usage.
x.format_commas(); // 12,345,678.112233
x.format_si('.'); // 12 345 678.112 233
// Customizable groupings, decimal marks, and grouping delimiters.
x.format_custom('#',':',4,2, false); // 12:34:5678#112233
// Customizing precision prior to grouping.
let y = 5512.332;
let pre_formatted = format!("{:.4}", x);
custom_group(&pre_formatted, ',', ' ', 3, 3, false); // 5 512,3320
}