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
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
I came up with a cool phrase to put down here, but i forgot it...
display it as a int not a float.
"Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"
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
I came up with a cool phrase to put down here, but i forgot it...
printf("/i",number) ;
"Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"
doesnt even work at all....
prints /i
or if you meant \i, it gives an 'unknown escape sequance' error.
I came up with a cool phrase to put down here, but i forgot it...
casting to int will truncate the fractional part.Code:float number = 1234.56; printf( "%f", (int)number );
Last edited by taylorguitarman; 03-14-2002 at 10:32 PM.
If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?
that doesnt work either.
now it just prints the number as ' 0.00000 ' no matter what.
I came up with a cool phrase to put down here, but i forgot it...
printf("%0.0f", f);
;-)
kooma - [email protected]
Sorry, I meant this:
printf( "%d", (int)number );
If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?
Well, you could just use:
printf("%.0f",f);
The .0 means 0 digits printed after the decimal point. .1 would mean 1 digit etc.
Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/
ahh...
beautiful!
I came up with a cool phrase to put down here, but i forgot it...
I really should stop visiting this board once I can't remeber the last time I slept(I think it was last tuesday :-)).
"Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"
For God's sake:
printf("%d",number);
"If you tell the truth, you don't have to remember anything"
-Mark Twain
Why is it %d for integers, instead of %i or something?????
PS: I'm ALWAYS fooled that % =96
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
>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,
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.Code:#include <stdio.h> int main ( void ) { long double d = 12345678987634534.0; printf ( "%.0lf\n", d ); return 0; }
>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
Last edited by Prelude; 03-15-2002 at 04:46 PM.
My best code is written with the delete key.