I am making some calculations with PHP and I don't want a number to be above 100. So, for example I want 50 + 80 to be 100 and not 130. Basically cap any result to 100. How can I achieve this?
You could use min
:
min($sum, 100)
This returns either $sum
if $sum < 100
or 100
otherwise.
You can just use the min
function:
$result = min($result, 100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With