I have a PHP function which returns a number, and I want to display it as a percentage from 1 - 100. Anything over 100 should just be reevaluated to 100. How can I do that?
$myvar = 120;
$my_percentage = <$myvar, max value is 100>
I'm using Laravel, if that helps. Thanks!
This is the simplest way for restricting the number
$my_percentage = min(100, $myvar);
If you want to ensure the value is always less than or equal to 100, then take the minimum (using min()) of the value and 100...
$my_percentage = min(100, $myvar);
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