Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.

Latest threads

Back
Top