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
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?
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Perhaps you didn't include the right header, and it implicitly declared it as returning int.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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