Hi,
I need to round a number. I tried using round from math.h but it's returning weird values
I am getting -524288.000000 ?????Code:double num1 = 0;
num1 = round(2.67);
printf("col = %f\n", num1);
Anybody can help with this
Amish
Printable View
Hi,
I need to round a number. I tried using round from math.h but it's returning weird values
I am getting -524288.000000 ?????Code:double num1 = 0;
num1 = round(2.67);
printf("col = %f\n", num1);
Anybody can help with this
Amish
Are using using a C99 implementation?
Perhaps you didn't include the right header, and it implicitly declared it as returning int.
I used #include <math.h>
and when i compile I added the flag -lm
I dunno what the c99 thingy is. Can someone explain more. Thanks
Amish
C99 is the new C standard.
round is a new function in C99.
Which OS/Compiler are you using?
What compiler options did you use?
Did you get any warnings?
$ gcc -std=c99 foo.c -lm
$ ./a.out
col = 3.000000
sorry for the late reply. I do not get any warnings using round without the -c99 flag. I finally created my own round function. But thanks for the info.
Amish