#utility #formatting #numbers

rust-functions

A collection of Rust utility functions (starting with format_number)

3 unstable releases

Uses new Rust 2024

0.2.1 Oct 1, 2025
0.2.0 Oct 1, 2025
0.1.0 Oct 1, 2025

#890 in Text processing

Download history 372/week @ 2025-10-01 23/week @ 2025-10-08 8/week @ 2025-10-15

403 downloads per month

MIT license

8KB
115 lines

rust-functions

A collection of small, reusable Rust utility functions.
The first release includes format_number, a helper for formatting numbers in a human-friendly way.

Installation

Add this to your Cargo.toml:

[dependencies]
rust-functions = "0.2.1"

Usage

The format_number function supports both &str and usize as the group size argument.

use rust_functions::number_formatting::format_number;

fn main() {
    // Default group size (3) when passing ""
    println!("{}", format_number("1234567", "")); 
    // → "001_234_567"

    // Explicit group size as string
    println!("{}", format_number("1234567", "4")); 
    // → "0123_4567"

    // Explicit group size as usize
    println!("{}", format_number("1234567", 4)); 
    // → "0123_4567"

    // Handles decimals
    println!("{}", format_number("1234.5678", 3)); 
    // → "001_234_decimal_point_567_800"

    // Handles negatives
    println!("{}", format_number("-1234", "")); 
    // → "negative_001_234"
}

License

MIT

No runtime deps