For example I want to print a value in c up to 2 decimal places, without rounding it off.
like:
a = 91.827345;
printf("%.2f", a);
will print 91.83
, but I want output to be 91.82
only. How to do it?
i'd suggest shorter and faster approach:
printf("%.2f", ((signed long)(fVal * 100) * 0.01f));
this way you won't overflow int, plus multiplication by 100 shouldn't influence the significand/mantissa itself, because the only thing that really is changing is exponent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With