cancel
Showing results for 
Search instead for 
Did you mean: 

Float wildcard precision limited to 6 digits ?

Emilmart
Senior

Hi,

I try to display a float with a precision of 9 number after the digit. My wildcard buffer size is set to 20.

Unicode::snprintfFloat(textArea1Buffer, TEXTAREA1_SIZE, "%.9f", 0.123456789f);
 
textArea1.invalidate();

My output when running the simulator is the following: 0.123457

Is the snprintfFloat format limited to 6 digits ?

I'm using TouchGFX Designer 4.17.0.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Emilmart
Senior

In the mean time I cast into an array this way all the digits are printed

char array[20];
 
sprintf(array, "%.9f", 0.123456789f);
 
Unicode::strncpy(textArea1Buffer, array, TEXTAREA1_SIZE);
 
textArea1.invalidate();

View solution in original post

3 REPLIES 3
TDK
Guru

Note that the precision of a 32-bit float itself is limited to about 6 digits. Printing more digits than that may be misleading.

If you feel a post has answered your question, please click "Accept as Solution".

This is strange because if I place myself in debug mode with a float number = 0.123456789f, I see that all the digits are kept, despite using 32-bit float

Emilmart
Senior

In the mean time I cast into an array this way all the digits are printed

char array[20];
 
sprintf(array, "%.9f", 0.123456789f);
 
Unicode::strncpy(textArea1Buffer, array, TEXTAREA1_SIZE);
 
textArea1.invalidate();