Problem with displaying float
Hello to Everyone
İ am using pic18f4620 and mplab c18. İ am trying to display float and it is working in such values 5, 5.17 or 5.177 but when i am trying to show 5.05 it is displaying 5.5. İt doesnt show 0 if it is first after point. a few sample
Real Value Displayed Value
4.006 4.6
2.01 2.1
and i know why it is working like this, in mplab c18 sprintf function doenst support to float--->string conversation. and in microchip support they are offering a code so that code is working like this. İt is not working well. Here is the code below
void display_float_t(float x){
char buffer[100];
unsigned long x_dec=0;
long x_int=0;
x_int = (long)((float) x);
x_dec = (long)((float)x*1000)-x_int*1000;
sprintf(buffer,(const far rom char*)"%li.%li", x_int,x_dec);
lcd_string( buffer);
}
when the result of the "x_dec = (long)((float)x*1000)-x_int*1000;" is starting with 0 like 07 or 007 it is taking it like 7 and displaying 7. so if anyhow would help me to solve this i would be so glad. Thanks for your helps.
Best Regard
Aslan OYMAK