Float to ASCII Conversion

Status
Not open for further replies.

Pepsiiuk

New Member
Hi all.

Im trying to convert a float to ASCII so it can be displayed on a GLCD. However, i have been searching the net for an hour and still have not found anything of use to me.

Im using a PIC18F87J50 and im programming it (in C) in MPLAB.

Any ideas?

Thanks
 
You should always opt for snprintf if your CRT supports it. In addition, specifying the precision is always a good idea

i.e.

/* format the string, making sure you don't overflow and printing only 3 numbers after dec point */
snprintf(buffer, sizeof(buffer), "%.3f", yourFloatVariable);

/* terminate the string, just in case you hit the last byte */
buffer[sizeof(buffer) - 1] = 0;

Some compilers (like the old hi-tech C) require you to specify that you need floating point in your printf library. Today this is done automatically, though.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…