MathUtils.Clamp

MathUtils.Clamp method

Clamp value to range [min, max]

public static double Clamp(double val, double min, double max)
ParameterTypeDescription
valDoubleValue to clamp.
minDoubleMinimum value.
maxDoubleMaximum value.

Return Value

The value between [min, max]

Examples

var val = 195;
//Clamp value to [0, 100]
var clampedValue = MathUtils.Clamp(val, 0, 100);
//This will output 100
Console.WriteLine($"Value = {val}");

See Also