cancel
Showing results for 
Search instead for 
Did you mean: 

Convert UNICODE::CHAR to Float

uilter
Senior

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.

7 REPLIES 7
Yoann KLEIN
ST Employee

Hello @uilter,

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

Best regards,

Yoann KLEIN
ST Software Developer | TouchGFX

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

Thanks.

@Yoann KLEIN I've tested. Unfortunately not works.
It only works with uint8_t or chars, not a unicode::char that is basically a uint16_t array.

Hello,

What about that ? 

double d = std::atof(reinterpret_cast<char*>(textArea1Buffer));

 

Yoann KLEIN
ST Software Developer | TouchGFX

Hi Yoann Klein, not possible. I tested here, but thanks for its suggestion.

t.decker
Senior II

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.

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.