0

This question already has an answer here:

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.

marked as duplicate by cuonglm, Rui F Ribeiro, HalosGhost, Wildcard, countermode Dec 2 '16 at 7:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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 2 '16 at 6:19
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.