DecimalFormat f = (DecimalFormat) getNumberInstance();
f.setGroupingSize(3);
s = f.format(1000);
<N extends Number> String format(N n, char g, char d) {
StringBuilder s = new StringBuilder();
char a[] = valueOf(n).toCharArray();
int i, m;
for (i = 0, m = a.length; i < m; ++i)
if (a[i] == d) {
s.append(a, i, m - i);
break;
}
while (i - 3 >= 0) {
s.insert(0, a, i - 3, 3);
if ((i = i - 3) > 0)
s.insert(0, g);
}
s.insert(0, a, 0, i);
return s.toString();
}
DecimalFormat decimalFormat = new DecimalFormat("#,###");
String formattedString = decimalFormat.format(1000000);
String.format("%,d", 1000000);
setlocale(LC_ALL, "");
printf("%'d\n", 1000);
string f = "%3,d".format(123456);
p := message.NewPrinter(language.English)
s := p.Sprintf("%d\n", 1000)
s :: Int -> String
s = intersperseN ',' 3 . show
intersperseN :: a -> Int -> [a] -> [a]
intersperseN x n = uncurry (<>) . foldr alg ([], [])
where
alg a (buf', acc)
| length buf >= n = ([], (x:buf) <> acc)
| otherwise = (buf, acc)
where buf = a:buf'
new Intl.NumberFormat().format(1000);
echo number_format(1000);
writeln(format('%.0n',[double(10000)]));
sub commify {
local $_ = shift;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}
'1000'.gsub(/\B(?=(...)*\b)/, ',')
'1000'.reverse.scan(/.{1,3}/).join(',').reverse
println!("{}", 1000.separated_string());