How to clamp a float?

Hi! I have a problem with clamping a float.
In UDK I had to just put Clamp(float, max, min) to get clamped value. I found this post:

but I’m not sure how to use it.
I included Fmath and put this:

FMath::Clamp(MyFloat, 0, 100);

but this is giving me a error:
error C2782: ‘T FMath::Clamp(const T,const T,const T)’ : template parameter ‘T’ is ambiguous

Can someone help me with this?

0 and 100 are integer constants, not floating point constants. The compiler doesn’t know whether you want to convert them to floats and do float-clamping, or convert your float to an int and do int-clamping.

To resolve the ambiguity, do FMath::Clamp(MyFloat, 0.0f, 100.0f).

2 Likes

Thank you!