What is the return value failed FCString::Atof?

Hello. Atof, Atoi those series of “string to numeric conversion” functions seems to risky.
Even official documents were not mentioned any of that.
(A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums)
Return value is god’s decision or 0 or what?
If return value is ‘0’ then how distinguish request ‘0’ with error ‘0’?.

Well Atof and Atoi returns float and an integer respectively. I’m not quite sure exactly what you’re asking about zero. The purpose of these functions is to convert text to a number, e.g.

FCString::Atoi(TEXT("2.625"))

Will evaluate to an integer value of 2.

UPDATE:

Following the implementation shows that it uses standard C++ wcstof() underneath. So if text cannot be parsed into a float it will return 0.0.

The case of next is just fine.
“int number = FCString::Atoi(TEXT(“2.625”))”
but if next return value is zero or what?
“int number = FCString::Atoi(TEXT(“Text…$$%$”))”
What is the invalidated case of “number”?

I’ve updated my original answer, so

int number = FCString::Atoi(TEXT("Text...$$%$"))"

number will evaluate to int 0.

How to distinguish error from zero?
For Example:

int32 er_number = FCString::Atoi(TEXT(“Some Text”));

and

int32 zero_number = FCString::Atoi(TEXT(“0”));

As possible workaround - to write your own input validator before calling atoi

Use FCString::IsNumeric to validate before conversion

1 Like