2023-06-19 10:10 AM
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.
2023-06-20 12:34 AM
2023-06-20 11:33 AM
Not yet. I'll try today and give you a feedback =)
Thanks.
2023-06-20 06:51 PM
@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.
2023-06-21 05:48 AM
Hello,
What about that ?
double d = std::atof(reinterpret_cast<char*>(textArea1Buffer));
2023-06-25 10:47 AM
Hi Yoann Klein, not possible. I tested here, but thanks for its suggestion.
2023-06-25 11:50 PM - edited 2023-06-25 11:54 PM
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?
2023-06-26 01:06 PM
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.