How to separate numbers in three-digit groups in C

Rouben Rostamian rouben at math16.math.umbc.edu
Mon Jun 24 03:45:50 AEST 1991


I need help with printing numbers (floating or integer) in C.  I would like
to display the numbers in three-digit comma-separated format.  For instance,
the integer 12345678 should be printed as 12,345,678.  The floating point
number 1234.56789 may be printed as 1,234.5678 or as 1,234.567,8.
I wish the printf function had an option for such formatting, but
as far as I know, it doesn't.  

I guess the ideal solution would be to extend the format options
for the printf command.  Perhaps a Printf function may be defined which
accepts the standard formatting strings of the printf function, but which
also accepts additional conversion characters to print comma-separated
digits.  I do not wish to re-invent the wheel if someone has already done
this.  So please let me know if there is something similar available somewhere.

--
Rouben Rostamian                          Telephone: (301) 455-2458
Department of Mathematics and Statistics  e-mail:
University of Maryland Baltimore County   bitnet: rostamian at umbc.bitnet
Baltimore, MD 21228,  U.S.A.              internet: rouben at math9.math.umbc.edu



More information about the Comp.unix.questions mailing list