-
Parsing float within JSON in C++yields values that do not match the data
-
In the blueprint, the data obtained and sent using the blueprint plugin[Json Blueprint Utilities] is incorrect
That’s not a bug. It’s a floating point issue. https://floating-point-gui.de/
But this plugin does not read the float correctly
What do you mean?
In JS language, you can correctly obtain number
Extracting Float from Json using UE’s library still has some deviations
The best way is to extract String from Json
This is normal C++ behavior.
The small deviation shouldn’t have any impact most of the time, but it’s something to be aware of. In most UE functions dealing with float/double, there is a Tolerance parameter (with a sensible default value) to mitigate the deviation, for example in FVector comparisons :
If you are comparing floats/doubles directly you should also take that into account :
float A = 0.1f + 0.3f;
// Don't do this
if (A == 0.4f)
{
//...
}
// Do this instead
if (FMath::IsNearlyEqual(A, 0.4f))
{
//...
}
// Or this
if (FMath::Abs(A-0.4f) <= UE_KINDA_SMALL_NUMBER)
{
//...
}
When it comes to displaying floats and doubles to screen, use a format to automatically handle rounding to the amount of decimals you need. Having a deviation at the 10th decimal isn’t gonna impact the number you display with 2-3 decimals.
Have the bugs been fixed?