Logo

Programming-Idioms

  • Pascal
  • Rust

Idiom #173 Format a number with grouped thousands

Number will be formatted with a comma separator between every group of thousands.

use separator::Separatable;
println!("{}", 1000.separated_string());

Requires the separator crate
uses sysutils;
writeln(format('%.0n',[double(10000)]));   

Formatting with thousandseparators only works for floating point values, hence the typecast.
Note that thousandseparator is locale dependant.
#define _POSIX_C_SOURCE 200809L
#include <locale.h>
#include <stdio.h>
setlocale(LC_ALL, "");
printf("%'d\n", 1000);

New implementation...
cup