1

I have 2 float values as

A = 0.0306880000
B = 0.0396640000

When I use printf to print as "%5.3f", A value is printed as 0.031 and B values is printed as 0.040. When I add the two values together, I get the answer 0.070 (which is 0.0306880000 + 0.0396640000).

How do I include only 3 decimal points to be taken in to the addition so that the answer would be 0.071 (0.031 + 0.040).

sazzad
  • 5,740
  • 6
  • 25
  • 42
anisha
  • 35
  • 7

1 Answers1

-1

You should round the value of A and B using this macro:

#define ROUND3(number) ( (int)( (number) * 1000 + 0.5 ) / 1000.0 )

test code

Divlaker
  • 401
  • 6
  • 16