Skip to content

format

typescript
Mathf.Clamp(val, left, right)

class: Mathf

description

Limits the given value to be within the given minimum float value and maximum float value. If the given value is within the minimum and maximum range, it returns the given value.

parameter

param_nametypedescription
valnumberThe given value.
leftnumberThe minimum float value.
rightnumberThe maximum float value.

return

typedescription
numberThe float result between the minimum and maximum values.

code example

typescript
// Returns the float result between the minimum and maximum values.
let result = Mathf.Clamp(5, 0, 10) // result = 5