help needed in a c program
here is a given c program which rounds off the floating value.
This job is to have the return amount in both calls to return 1.32.
Now the 1.324 returns 1.32000001..this is not acceptable, this must return the correct rounding values.
//***************************************************************//
//***************************************************************//
void TestTax()
{
float Tax_Amt1 = 1.324;
float Tax_Amt2 =1.325;
float Ret_Amt;
Ret_Amt = Round_Money(Tax_Amt1);
Ret_Amt = Round_Money(Tax_Amt2);
}
//***************************************************************//
//***************************************************************//
float Round_Money(float In_Amt)
{
char temp1[32];
char temp2[32];
float Ret_Amt;
int t1,t2;
float r1,r2;
int v1,v2;
int t=0;
sprintf(temp1,"%.3f",In_Amt);
In_Amt = atof(temp1);
t1 = abs(In_Amt);
r1 = In_Amt - t1;
sprintf(temp1,"%.03f",r1);
temp2[0] = temp1[4];
temp2[1] = 0;
v1 = atoi(temp2);
r2 = atof(temp2);
sprintf(temp1,"%.2f",In_Amt);
temp1[4] = '0';
In_Amt = atof(temp1);
if(v1 > 4)
{
In_Amt = In_Amt +.01;
sprintf(temp1,"%.2f",In_Amt);
Ret_Amt = atof(temp1);
}
else
{
sprintf(temp1,"%.2f",In_Amt);
Ret_Amt = atof(temp1);
}
return Ret_Amt;
}
i am not able find the problem here..can you please help me out. it needs to round off 1.324 and 1.325 to 1.32