Formatting for large values 
Author Message
 Formatting for large values

Could someone please tell me how to get a printf statement (or some
suitable equivalent) to print commas between groups of three in a long or
unsigned long?

such as $1,000,000,000,000  ?

Perhaphs there is a special formatting sequence in printf I'm unaware of?

Thanks,
Tracy



Fri, 28 Feb 1997 17:10:54 GMT  
 Formatting for large values

Quote:

>Could someone please tell me how to get a printf statement (or some
>suitable equivalent) to print commas between groups of three in a long or
>unsigned long?

>such as $1,000,000,000,000  ?

>Perhaphs there is a special formatting sequence in printf I'm unaware of?

I've never found a way to get printf to do this. I simply (not so
simple, actually) use sprintf and strcat to load a string with the
actual value, using division (which truncates) and modulo arithmetic
to parse the groupings of three, interspersed with concatenated
commas. Handy because you can also put the '$' at the beginning.


**  If it doesn't dim the lights when you power it up,
**  it ain't a REAL computer!



Sat, 01 Mar 1997 12:13:09 GMT  
 Formatting for large values

Hi there,

I am looking for a C-function which is similar to the READKEY function in
 Pascal. Also this routine should work on a UNIX-machine (SUN).
getc or getchar would not match because they are just reading the buffer i.e.
I have to press return to get the typed in character.

Thanx
  Reiner



Mon, 10 Mar 1997 23:39:15 GMT  
 Formatting for large values

Quote:
> Hi there,
> I am looking for a C-function which is similar to the READKEY function in
>  PASCAL. Also this routine should work on a UNIX-machine (SUN).
> getc or getchar would not match because they are just reading the buffer i.e.
> I have to press return to get the typed in character.

There is no simple answer to this question.  However, there is a lazy
answer:

system("stty -echo raw");
c=getchar();
system("stty echo -raw");

Hrv

--

                                                       ///
This message originates from:                         (o o)
---------------------------------------------------ooO-(_)-Ooo-------
Hrvoje Niksic, F&SF reader, college student in his free time





Thu, 13 Mar 1997 18:51:14 GMT  
 Formatting for large values
Try the scanf function.

                Ghislain.



Sat, 22 Mar 1997 16:10:09 GMT  
 Formatting for large values
: Try the scanf function.

I suppose you don't think you get enough email.  Well you should get
plenty now.  scanf is no substitute for READKEY.  You still have to
press enter to get the character into the program.  Please read the
FAQ carefully.  There is no standard, portable way to do that but
there are some system specific methods.

As the FAQ points out you should also check the FAQ for the system
you want to do this on.

--

Planix, Inc.                        |   Democracy is three wolves and a
Toronto, Ontario, Canada            |   sheep voting on what's for dinner.
+1 416 424 2871  (DoD#0082) (eNTP)  |



Tue, 25 Mar 1997 11:18:43 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Largest double value ...

2. How C Handle Value Larger than 32 bit?

3. Largest Value of Integer

4. Value too large for defined data type

5. very large integer values

6. Setting Large (Binary) values in Registry

7. Setting large binary values in registry using RegSetValueEx

8. Largest Value revisited

9. GetTextExtent() returning too large a value?

10. How to format a currency value of zero as blank

11. Printf: Formatting numeric values

12. Formatting object values in the watch window

 

 
Powered by phpBB® Forum Software