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.
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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.