0

Why function round isnt working?

#include <math.h>
#include <stdio.h>
int main(void)
{
   float y = round(12.59);
   float k = y*100000000000000;

   printf("%f\n",k);
}

The result of this program is 1300000030064640.000000

If 12.59 is rounded to the nearest integer (13) why the result of this multipliyng contains so odd number? I know that i can trasnform my float into int, but what to do if i need to store a bigger number than int can hold?

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
susi33
  • 207
  • 1
  • 2
  • 4
  • that is caused by loss of precision – meskobalazs Dec 05 '14 at 15:26
  • [Is floating point math broken?](http://stackoverflow.com/questions/588004/is-floating-point-math-broken) No, read [What Every Programmer Should Know About Floating-Point Arithmetic](http://floating-point-gui.de/) and [What Every Computer Scientist Should Know About Floating-Point Arithmetic](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) – phuclv Dec 05 '14 at 15:29

0 Answers0