round the float value to 2 decimals before use :
Code:#include <math.h> float round(float f) { return floor(f+0.5); } ... float amount = 1.23456; amount = round(amount*100)/100; printf ("1.23456 rounded to 2 decimals is : %f", amount); ...
round the float value to 2 decimals before use :
Code:#include <math.h> float round(float f) { return floor(f+0.5); } ... float amount = 1.23456; amount = round(amount*100)/100; printf ("1.23456 rounded to 2 decimals is : %f", amount); ...