Sep 6, 2008 at 4:35am Sep 6, 2008 at 4:35am UTC
Ok, I have to do an operation like this:
454*22.76 = 10 333.04
Thats ez, but then I have to only print to screen the last two digits, the 33.
How would I do this, to multiply two integers then make the product a double then only print out the last two digits?
Would I have to assign something to each number and only print out n1 and n2?
Im lost lol
Last edited on Sep 6, 2008 at 4:39am Sep 6, 2008 at 4:39am UTC
Sep 6, 2008 at 5:43am Sep 6, 2008 at 5:43am UTC
Can't you do that with C style print such as:
printf("The number is %2.0f \n", number);
I like the modulo, but that wouldn't help for getting rid of the decimal places would it?
Sep 6, 2008 at 5:54am Sep 6, 2008 at 5:54am UTC
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
int main(){
for (int a=0;a<80;a++)
printf("." );
printf("%2.0f\n" ,1024.48);
printf("%2.0f\n" ,4.48);
for (int a=0;a<80;a++)
printf("." );
return 0;
}
Output:
................................................................................
1024
4
................................................................................
Actually, since modulo only works on integers, the values would be converted to int and then operated upon.
Last edited on Sep 6, 2008 at 5:57am Sep 6, 2008 at 5:57am UTC
Sep 6, 2008 at 6:00am Sep 6, 2008 at 6:00am UTC
Yeah, I'm on my computer that doesn't have the code interface set up right now so I couldn't test it. I was almost positive there was a way to do this though, but looking at the formatters now, I'm not so sure.
Sep 8, 2008 at 6:03am Sep 8, 2008 at 6:03am UTC
if you like the modulo:
force the long to an int by n=(int n)
then use %.