How to convert a float variable to a string in C18 using the sprintf or printf functions.
You can download here Microchip's document which explains in more detail the above:
Here is an example of this conversion: in the segment of program shown below, the variable 'a' which was previously defined as floating point, is converted to its whole part and a decimal part (both variables must be previously declared as integers).
Finally, in the sprintf function, the variables whole and decimal are handled with fixed point and converted to a string (named array), to later display in the LCD of the system.
Please note how the decimal part can be set to 1 digit (multiplying by 10), 2 digits (multiplying by 100) and so on.
The complete example source program for the Bolt 18F2550 system, which reads DS18B20 temperature sensor and displays centigrades and farenheit on the LCD, is as follows:
Similar method should be used with the printf( ) function.