Help with touch shield and displaying floating point

Cant get it to display a simple floating point. anybody help me figure out what to do. I tried the code below,

char xtr[20];
float x;

x=.01;

void loop(){
x++;
sprintf(xtr,"x= %f ",x);
Tft.fillRectangle(0,140,144,16,0);//fill area with black (clear text)
Tft.drawString(xtr,0,140,2,WHITE);

Thanks.

I had the same problem, like the arduino sprintf doesn’t work, finally can only try to write their own floating point the transformation of the function character groups.

not sure I get what you mean, how did you figure it out?

no one knows?

you can try this function that change “float” to “string”.

int digits :the number of digits behind decimal point

[code]char *_ftoa(double n, char *s, int digits)
{
memset(s , 0 , sizeof(s));
int i = 0 , p;
char sign = true;
if( n < 0 )
{
sign = false;
n = -n;
}
long long t = (long long)n;
n = n - t;
if( t == 0)
{
s[i++] = ‘0’;
}
else
{
while( t != 0 )
{
p = t % 10;
t /= 10;
s[i++] = p + ‘0’;
}
if(!sign) s[i++] = ‘-’;
}
if( fabs( n - 0.0 ) > 0.0000000000001)
{
s[i++] = ‘.’;
int cur_d = 0;
while( cur_d < digits)
{
cur_d++;
n *= 10.0;
p = (long long)n;
n = n - p;
s[i++] = p + ‘0’;
}
}
s[i] = ‘\0’;

}[/code]