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.
This has come up so many times it is unbelievable. First you must understand how floating point arithmetic works. Do a google search for 'floating point' and read up a bit. You can start here: www.petebecker.com/.../js200006.html
Regards, - mike
Thanks mike..the document has been of great help
Regards, Bhushan