Clamping floating numbers in Python?

There’s no such function, but

max(min(my_value, max_value), min_value)

will do the trick.

Leave a Comment