Skip to main content
uilter
Senior
June 19, 2023
Question

Convert UNICODE::CHAR to Float

  • June 19, 2023
  • 2 replies
  • 3319 views

Hi,

I'm try to convert a unicode::char to a float.
I not find a function to do it. https://support.touchgfx.com/4.20/docs/api/classes/classtouchgfx_1_1_unicode

In C language, I used to using a simple char with iotf() to convert it.

Today I'm following this steps:
- read the textArea Unicode::char, convert it to a char type in a new buffer
- with this new char buffer I'm using the itof to convert to a float

The cons about this method is I need to create another buffer to it.
Please, anyone could you guide me how to do it in a smart way?

Thank you.

This topic has been closed for replies.

2 replies

Yoann KLEIN
ST Employee
June 20, 2023

Hello @uilter,

Did you already try with std::atof or std::stof ?

Best regards,

Yoann KLEINST Software Developer | TouchGFX
uilter
uilterAuthor
Senior
June 20, 2023

Not yet. I'll try today and give you a feedback =)

Thanks.

Senior II
June 26, 2023

Before using the std:: functions for converting a string to float, you have to convert the UnicodeChar (which is a uint16_t artay) to a cstring using

 

Unicode::toUTF8(unicode, utf8, maxbytes)

 

Edit: You did this already and asked for a solution without the need of an extra buffer. Then maybe have look into the sourcecode of std::atof and modify it for reading a UnicodeChar instead of the string?

When this account seems to be inactive, try @tdecker2 - ST can't change mail addresses, so I had to create a new account.
uilter
uilterAuthor
Senior
June 26, 2023

Hi @t.decker 

This is my goal, looking for a function in TouchGFX that do it without the needs to create a second buffer.

No, I did not see it, but I think it will be the way.

Maybe it can be implemented in a near future in Touchgfx. Let's wait.