0

I am using the following command on Terminal in MacBook.

printf "The number is %'d\n" 123456

I expect the output:

The number is 123,456.

But I am getting:

The number is 123456.

Please point out my mistake.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • While on first glance it looks like a duplicate, this question is actually asking why the printf answer doesn't work for him/her. – Anthony Geoghegan Nov 23 '16 at 11:25
  • It works for me on macOS 10.11.6. What country are you in (and what language did you set your computer to during installation)? Edit into the question. – Wildcard Dec 02 '16 at 06:19

1 Answers1

3

Please point out my mistake.

I guess you mean this:

printf "%'.3d\n" 123456
123,456

Bear in mind that the separator depends on your locale.

LC_NUMERIC="en_US.UTF-8"
printf "%'.3d\n" 123456
123,456

LC_NUMERIC="sv_SE.UTF-8"
printf "%'.3d\n" 123456
123 456

There is a good description available here.