That above does work. Your problem lies somewhere else. This does the rounding only once, so if your float changes via calculations you need to round it again every time.
Rounding a float is not that simple. Floats are by design not 100% accurate so if you want a 100% accurate number you will need to use integers. Floats are used because they can display very large numbers without requiring a lot of memory and overhead.
So you have two options either format the float using “Float To Text” as mentioned above or convert the float to an Integer.
For anyone else coming here late to the game… the Float to Text to Float if you need it is:
float x = FCString::Atof(*FString::SanitizeFloat(FMath::FRandRange( min, max )).Left(precision + 2));
replace “FMath::FRandRange( min, max )” with your float.
I second that this is a smart and flexible approach, considering i’m not aware (as a beginner) of any native node to handle such. I tested this macro and works all good.
I added extra output pins to this macro for my own needs (e.g. String type which plug in straight to the PrintDebug = saves some extra nodes to keep things clean).
I solved this by using this division node, taking the integer value and concatenating with the truncated remaining. One decimal, multiply by 10, two decimals, 100 etc…