Convert float to string

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hie,

   

Does anyone know how I can convert a float into a string on the psoc5 (gcc compiler)? I would like to convert floats into strings so that I can display on my GLCD which has library functions for displaying only string types.

0 Likes
2 Replies
Anonymous
Not applicable

I just discovered that the sprintf() function works perfectly for this conversion. The syntax is something like this:

   

float a = 4.8375;

   

char a_text[9];

   

sprintf(a_text,"%f",a);

   

a_text[4] = '\0';

   

 

   

this will return the string 4.84

Anonymous
Not applicable

Hi Liberty,

   

 

   

Thank you for sharing this on the forum !

0 Likes