Skip to main content
Emilmart
Associate III
September 27, 2021
Solved

Float wildcard precision limited to 6 digits ?

  • September 27, 2021
  • 3 replies
  • 1600 views

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

This topic has been closed for replies.
Best answer by Emilmart

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();

3 replies

TDK
September 27, 2021

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""."
Emilmart
EmilmartAuthor
Associate III
September 27, 2021

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
EmilmartAuthorBest answer
Associate III
September 28, 2021

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();