I’m looking to format a Long Float as currency in C. I would like to place a dollar sign at the beginning, commas iterating every third digit before decimal, and a dot immediately before decimal. So far, I have been printing numbers like so:
printf("You are owed $%.2Lf!\n", money);
which returns something like
You are owed $123456789.00!
Numbers should look like this
$123,456,789.00
$1,234.56
$123.45
Any answers need not be in actual code. You don’t have to spoon feed. If there are C-related specifics which would be of help, please mention. Else pseudo-code is fine.
Your
printfmight already be able to do that by itself with the'flag. You probably need to set your locale, though. Here’s an example from my machine:And running it:
This program works the way you want it to both on my Mac (10.6.8) and on a Linux machine (Ubuntu 10.10) I just tried.