Float FJsonObject::GetNumberField returns wrong values

Hei,

It seems that float FJsonObject::GetNumberField returns wrong values. It’s not always wrong, but maybe every two numbers in the 16842749 area.

I can reproduce it very easily with the following code. numberFloat and numberDouble should mean 16842749 in both cases, but the float version is different.

FString jsonDocument(TEXT("{\"Id\":16842749}"));
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
TSharedRef< TJsonReader<> > JsonReader = TJsonReaderFactory<>::Create(jsonDocument);

if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
{
	float numberFloat = JsonObject->GetNumberField(FString(TEXT("Id")));
	double numberDouble = JsonObject->GetNumberField(FString(TEXT("Id")));
	
	GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, 
		FString::Printf(TEXT("Id float: %f\nId double: %f"),
			numberFloat, numberDouble));
}

129496-2017-03-10+23_03_06-démarrer.png

My bad, Unreal only implements the double version. It’s a float issue.

VaRest cast the double to float, so I guess the problem is from VaRest that uses floats when it should use double.