cancel
Showing results for 
Search instead for 
Did you mean: 

how to display the value in float using snprintf?

Angle
Associate II

Hi, how can i use the snprintf for float value in touchgfx? I want to display the data from the sensor in touchgfx lcd but in float

1 ACCEPTED SOLUTION

Accepted Solutions

it also depends on what C library is used. Nano version doesn't have float support. Besides of this TouchGFX requires Unicode strings.

So, I use

Unicode::snprintfFloat(buffer, bufSize, "%f", var );

View solution in original post

12 REPLIES 12
gbm
Lead III

And why don't you check snprintf() in C standard library reference? There are no mysteries - just read the documents. Print formats are common fo all *printf functions. To use floating point formats you must enable float printf library support as suggested by the compiler - look at the compiler messages when using the %f format for the first time.

it also depends on what C library is used. Nano version doesn't have float support. Besides of this TouchGFX requires Unicode strings.

So, I use

Unicode::snprintfFloat(buffer, bufSize, "%f", var );

i have tried it before but its display % instead of float number from the sensor

Check your MCU settings

Option "Use float with printf from newlib-nano" should be enabled. And you can also play with different types of runtime libraries (Standart/reduced)​

KiptonM
Lead

They are telling you to do this:

Project->Properties->C/C++ Build->Settings->Tool Settings(Tab)->MCU Settings

Then check the box that says Use float with printf from newlib-nano (-u _printf_float)

Yoann KLEIN
ST Employee

Hello @Angle​ ,

I just tried it with snprintfFloat and it works. Also, it is specified in the documentation that snprintf only works with %c (element type: char), %s (element type: null-terminated UnicodeChar list), %u, %i, %d, %o, %x formats.

Please let us know if that solved your issue.

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX

hi, so I need to convert floating-point to char first right? let say I have value -1.23, so I need to convert one by one right? can I get any example or where to refer on how to convert it ?

Hello,

If you use snprintfFloat you don't have to convert anything, it will work with your float value.

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX

Hi again,

i try using to send this data but it not update the wildcard area? can you help to see what wrong with my code

btw im send directly to screen2view.cpp. not modified any of file

0693W00000Y9f56QAB.png