Function format_with_underscores

Source
pub fn format_with_underscores(amount: impl Into<u64>) -> String
Expand description

Formats a number with underscores as thousand separators for improved readability.

This function takes a numeric value and formats it with underscores between each group of three digits to improve readability of large numbers. For example, 1000000 becomes 1_000_000.

§Arguments

  • amount - Any value that can be converted to u64

§Returns

A string with the formatted number

§Examples

assert_eq!(format_with_underscores(1000_u64), "1_000");
assert_eq!(format_with_underscores(1234567_u64), "1_234_567");
assert_eq!(format_with_underscores(1_u64), "1");