Skip to main content

format_number

Function format_number 

Source
pub fn format_number<T>(n: T) -> String
where T: Integer,
Expand description

Formats an integer with comma thousands-separators.

Accepts any itoa::Integer, so both signed and unsigned widths work. Uses itoa to render the digits into a stack buffer, then inserts commas every three digits from the right — no intermediate String allocation for the conversion itself.

§Examples

use vct_core::utils::format_number;

assert_eq!(format_number(0), "0");
assert_eq!(format_number(1234), "1,234");
assert_eq!(format_number(1_234_567), "1,234,567");