Get Float As String With Precision Using Epic’s FText Helpers
Dear Community,
I’ve updated my Get Float As String With Precision node to
-
Be pure (no exec chain)
-
Utilize Epic’s FText C++ code to leverage of their hard work on float decimal precision.
-
Add bool to make the leading 0 optional, so 0.5 could be shown as 0.5 or .5 depending on your preferences!
Yay!
**My C++ Code For You!**
Here's how it works in C++ !
```
void UVictoryBPFunctionLibrary::StringConversion__GetFloatAsStringWithPrecision(float TheFloat, FString & FloatString, uint8 Precision, bool IncludeLeadingZero)
{
FNumberFormattingOptions NumberFormat; //Text.h
NumberFormat.MinimumIntegralDigits = **(IncludeLeadingZero) ? 1 : 0;**
NumberFormat.MaximumIntegralDigits = 10000;
NumberFormat.MinimumFractionalDigits = **Precision;**
NumberFormat.MaximumFractionalDigits = **Precision; **
FloatString = FText::AsNumber(**TheFloat**, &NumberFormat).ToString();
}
```
**Latest plugin download is here: (about 8 mb) **
Enjoy!