I know of two ways, but neither can be done through how
The way I would do it would be to multiply the value by
100 and cast it to an
int, which would cut off any remaining decimal values. Then, I would return it to a
float and divide by
printf(%.2f\n", (float((int)(cash * 100))) / 100.0. You might be able to do this without explicitly casting it back to a
float, but I never risk it.
You could also use the
trunc function from the
math.h library. This would be similar in use to the method above:
Either of these should work, but I prefer using the first option as it doesn't require any extra knowledge about how an outside function works, and is therefore more obvious to anyone else that reads the code.