This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Precision in float variables.

Hi,

I had simulated the following code using C166 compiler

float idata fval;
void main( void )
{

char cnv_str[30]= {'\0' };

      fval = 100.578;
      sprintf( cnv_str, "%f", fval );
      printf("format_data_str = %s\n\r",cnv_str);
      printf("fval = %f\n\r",fval);
      while(1);
}


I obtained the foolowing result after executing the code
format_data_str = 100.578003.
fval = 100.578003.
The result value is different from the one that was stored in the variable. The result value should have been 100.578000 instead of 100.578003.
Please let me know the possible casuse of this problem. If this is a compiler error then suggest me how to overcome this problem.
Thanks in advance.