cancel
Showing results for 
Search instead for 
Did you mean: 

snprintfFloat prints incorrectly some numbers

Tuoman
Senior II

For example Unicode::snprintfFloat 70000.700f with "8.2f" incorrectly prints "70000.71", while snprintfFloat 60000.700 with "8.2f" correctly prints "60000.70"

Test code:

Unicode::snprintfFloat(textArea1Buffer, TEXTAREA1_SIZE, "%8.2f", 70000.700f);
 
Unicode::snprintfFloat(textArea2Buffer, TEXTAREA2_SIZE, "%8.2f", 60000.700f);

Output:

70000.71
60000.70

I can circumvent this by using regular snprintf() which prints this correctly, but any idea why this would print this example wrong? Unfortunately the snprintfFloat is closed-source function. Please fix.

4 REPLIES 4
AScha.3
Chief II

i suppose, this is effect of rounding and "number representation" , decimal -> binary.

try: show full number, -> _SIZE, "%f ", 70000.700f ); (then we see, what number the cpu handels..)

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

@Romain DIELEMAN​ can you look at this, the float should be able to display 7 digits

snprintf() apparently works, but it might be using doubles internally.

Related

https://community.st.com/s/question/0D53W00000908ggSAA/how-to-write-decimal-figures-to-touchgfx-text-box

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Osman SOYKURT
ST Employee

Hello Tuoman & Tesla DeLorean,

Thanks for reporting this, I reproduced the issue on my side, we're going to investigate on that.

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX
Osman SOYKURT
ST Employee

Hello Tuoman & Tesla DeLorean,

We have a patch ready for the next version of TouchGFX Designer (4.22.0)

Meanwhile as workaround I can suggest you to use normal snprintf to convert float to char string in a temporary buffer. Then use Unicode::strcpy or similar to convert to unicode.

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX