How do I convert a float to FString?
I’m trying to print a debug message.
float f = 1.0f;
if (GEngine)
{
GEngine->AddOnScreenDebugMessage( -1,1.0,FColor::Red, TEXT(f) );
}
How do I convert a float to FString?
I’m trying to print a debug message.
float f = 1.0f;
if (GEngine)
{
GEngine->AddOnScreenDebugMessage( -1,1.0,FColor::Red, TEXT(f) );
}
Dear Pinheiro,
To convert float to Fstring you do this:
FString TheFloatStr = FString::SanitizeFloat(f);
To get the TCHAR version of this FString quickly you can do this
*TheFloatStr
so the final result is:
FString TheFloatStr = FString::SanitizeFloat(f);
GEngine->AddOnScreenDebugMessage( -1,1.0,FColor::Red, *TheFloatStr );
to convert FString to float I have tutorial on this here:
http://forums.epicgames.com/threads/973803-Tutorials-Entry-Level-UE4-C-Overview-Q-amp-A-New-Working-with-Config-Files-C?p=31686875&viewfull=1#post31686875
If this answers your question please mark the checkmark by my answer so others know it is resolved
Rama
That worked, thanks!
SanitizeFloat seems to expect >=0, is there another function who doesnt?
FString FString::SanitizeFloat( double InFloat )
{
// Avoids negative zero
if( InFloat == 0 )
{
InFloat = 0;
}
FString::Printf(TEXT("%f"),InFloat);