UE5.4.0 FCString::Atof precision issue vs sscanf %lf

Hi,

I have a wrong result using FCString::Atof . Using C++ way is ok.

Take this code :

//TEST
FString Fstr = TEXT("12345.0123456789");
double test_double;
test_double = FCString::Atof(*Fstr);
UE_LOG(LogTemp, Warning, TEXT("test_double : %.10f"), test_double);

std::string test2_str = std::string(TCHAR_TO_UTF8(*Fstr));
double test2_double;
sscanf(test2_str.c_str(), "%lf", &test2_double);
UE_LOG(LogTemp, Warning, TEXT("test2_double : %.10f"), test2_double);

Here his result :

[2024.05.01-08.33.03:261][116]LogTemp: Warning: test_double : 12345.0126953125
[2024.05.01-08.33.05:875][116]LogTemp: Warning: test2_double : 12345.0123456789

image

Why using FCString::Atof return wrong result ? How to use it and have correct result ? I’m using UE5.4.0

1 Like

ok found the answer : I need to use Atod not Atof

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.