I wrote a small program to demonstrate a problem im having with a bigger one so you dont have to look thru so much code. I'm having problems when I convert a double to an integer.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
double dNum;
int iNum;
char sNum[15] = "";
printf("Changing a double to int.\n");
printf("Enter a double: ");
fgets(sNum, 15, stdin);
dNum = (atof(sNum))*100;
printf("Double: %f\n", dNum);
iNum = ((int)dNum);
printf("Int: %d\n", iNum);
getch();
return 1;
}
The input:
2499.99
The output:
Double: 249999.000000
Int: 249998
Why does it minus one from itself? And how do i make it NOT minus one off itself? Thanks in advance...