# big numbers

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 03-14-2002
...
big numbers
how do i display a floating point number without the decimals.

I.E., how do i make this:

//code:
printf("%f", number);

//output:
1.00000

look like this:

//code
printf("%f", number);

//output
1
• 03-14-2002
Isometric
display it as a int not a float.
• 03-14-2002
...
no no.... you dont understand...... maybe i should make it more clear:

how do i turn this:

//code
printf("%f", number);
//output
99999999999999999999999999999.00000

into this:

//code
printf("%f", number);
//output
99999999999999999999999999999
• 03-14-2002
Isometric
printf("/i",number) ;
• 03-14-2002
...
doesnt even work at all....

prints /i

or if you meant \i, it gives an 'unknown escape sequance' error.
• 03-14-2002
taylorguitarman
Code:

```float number = 1234.56; printf( "%f", (int)number );```
casting to int will truncate the fractional part.
• 03-15-2002
...
that doesnt work either.

now it just prints the number as ' 0.00000 ' no matter what.
• 03-15-2002
kooma
printf("%0.0f", f);

;-)
• 03-15-2002
taylorguitarman
Sorry, I meant this:

printf( "%d", (int)number );
• 03-15-2002
Justin W
Well, you could just use:

printf("%.0f",f);

The .0 means 0 digits printed after the decimal point. .1 would mean 1 digit etc.
• 03-15-2002
...
ahh...

beautiful!
• 03-15-2002
Isometric
my mistake
I really should stop visiting this board once I can't remeber the last time I slept(I think it was last tuesday :-)).
• 03-15-2002
CodeMonkey
For God's sake:

printf("%d",number);
• 03-15-2002
Magos
Totally useless question
Why is it %d for integers, instead of %i or something?????

PS: I'm ALWAYS fooled that % =96 :)
• 03-15-2002
Prelude
>Why is it %d for integers, instead of %i or something?????
Both are allowed, but there are differences in how they behave and should be used.

For printf, %d and %i are both flags for signed decimal notation. For scanf, %d is a decimal integer pointer and %i is an integer pointer which may be of a base other than decimal.

%i isn't used often because it's better to be explicit in how you are representing the base with %o, %x, and %d.

Btw,
Code:

```#include <stdio.h> int main ( void ) {   long double d = 12345678987634534.0;   printf ( "%.0lf\n", d );   return 0; }```
Fiddle with this a bit, you'll find that you can remove the decimal and anything that follows with a %.0 flag, and a long double will give you a precision up to 17 digits.

>printf( "%d", (int)number );
Have you tried this? It works okay as long as the number is small enough to fit in an integer, otherwise you get incorrect output.

>printf("%d",number);
No, and test something before you offer it as a solution.

-Prelude
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last