Clamping a variable in c++

hello
i have a float variable that represent health and i wanted to know how to clamp it so it doesn’t go over 100
i should use clamping but i don’t know how

i know that this is very obvious but i’m still learning c++ so plz bare with me and thankyou

Hello, Amiot

To clamp a value in C++, you can use FMath::Clamp function:

template<class T>
static T Clamp
(
    const T X,
    const T Min,
    const T Max
)

It clamps X to be between Min and Max (inclusive).

Hope this helped!

Have a great day!