I have a value assigned to a variable called x (float) of 12.56.
I have another int variable called y. If I want to output 12 (from the 12.56) i can do:
y = x;
printf("%d", y); /*truncates the 12.56 and out puts 12 only*/
Any ideas how I just output the .56 of the 12.56??
Here is a sample of what you could do:
float x = 12.56f;
y = (int)x;
printf("%d plus %.2f equals %.2f\n", y, (x - y), x);
/* %.2f will display float values with decimal precision of 2. */
printf("%f", Var-(float)((int)Var) );
I just made that up, not sure if it works however. This is what it does:
(int)Var //12.56 --> 12
(float)(...) //(int)12 --> (float)12
Var - (...) //12.56 - 12 --> 0.56