root@ozdaltx.UUCP (root) (12/13/89)
In the back of my mind, it seems like I read that there is a format character used in printf(C) that allows the formatting of numbers. I'd like to take a number, ie. 123456.78 and print it as 123,456.78 . If this info is in the manual (SCO), I can't find it or it is not written clearly enough to say that what it does. If printf does not have this ability, it should be added. thanks in advance.... Scotty {ames,rutgers,texsun,smu}!attctc!ozdaltx!sysop
karl@haddock.ima.isc.com (Karl Heuer) (12/14/89)
In article <5761@ozdaltx.UUCP> root@ozdaltx.UUCP (root) writes: >[Can printf() format numbers with embedded commas?] Not in K&R or ANSI C, though it's conceivable that some vendor has added it as an extension. You may be thinking of the localization features of ANSI C. These provide some support for determining what the local convention is (e.g. where to place the commas, what the currency symbol looks like, etc.), but there's no library function that actually makes use of any this information (except for the decimal-point character). >If printf does not have this ability, it should be added. I think a better idea is to have a separate function to do this type of formatting, then print it with %s. (Just like you have to do with a time_t, for example, to make it print in a human-readable format.) I suspect this is what the Committee had in mind. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
javiv@nsi.UUCP (Javier Vilarroig Christensen.) (12/20/89)
In article <5761@ozdaltx.UUCP> root@ozdaltx.UUCP (root) writes: >In the back of my mind, it seems like I read that there is a format >character used in printf(C) that allows the formatting of numbers. [lines deleted] >If printf does not have this ability, it should be added. > >thanks in advance.... >Scotty It's imposible to do this with printf. You must make a funtion to do it in a string, and then feed it to printf. -- +------------------------------------+-------------------------------------+ | Javier Vilarroig Christensen | PHONE: 34 3 210-33-55 (VOICE) | | NEXUS Servicios de Informacion S.L.| 34 3 214-72-62 (DATA) | +------------------------------------+-------------------------------------+ | SMAIL: Travesera de Dalt 104 Ent. 5| EUNET: javiv@nsi.es | | 08024 - Barcelona - Spain | javiv@nexus.nsi.es | +------------------------------------+-------------------------------------+
jpr@dasys1.UUCP (Jean-Pierre Radley) (12/24/89)
In article <5761@ozdaltx.UUCP> root@ozdaltx.UUCP (root) writes: >In the back of my mind, it seems like I read that there is a format >character used in printf(C) that allows the formatting of numbers. >I'd like to take a number, ie. 123456.78 and print it as >123,456.78 . >If printf does not have this ability, it should be added. And make allowances for European conventions too, eh? In the meantime, while working on a General Ledger program which used 'awk' for formatting, I found the same limitation in the 'printf' function of 'awk'. So I wrote a sed filter to insert my commas: sed -f comma.sed <infile >outfile where comma.sed is: # comma.sed, inserts commas in numbers preceded by enough blanks : R /[0-9][0-9][0-9[0-9][,.]/s/ \([-+0-9]*[0-9]\)\([0-9][0-9][0-9][,.]\)/\1,\2/g t R I noted, along the way, that a sed script allows ONE commented line at the outset. -- Jean-Pierre Radley jpr@jpradley.uucp New York, NY 72160.1341@compuserve.com
bill@twwells.com (T. William Wells) (12/29/89)
In article <11443@dasys1.UUCP> jpr@dasys1.UUCP (Jean-Pierre Radley) writes:
: I noted, along the way, that a sed script allows ONE commented line at the
: outset.
try:
sed -e cmd1 -e cmd2 ....
or:
sed 'cmd1
cmd2'
---
Bill { uunet | novavax | ankh | sunvice } !twwells!bill
bill@twwells.com