Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Percentage amount

I am looking at displaying a text percentage amount. So if your life is a maximum of 1,000 and you currently have 200 health, it shows Health: 20%

Anyone know how I can take 0 to the max health number?

0 = 0%
1 = 1%
Max Health = 100%

and whatever in between. This would be a huge help, thank you.

Edit: By the way it'd be grabbing database values like \$user['currenthealth'] and \$user['maxhealth']

• PHP Code:
``` \$percent_health = (\$user['currenthealth']/\$user['maxhealth'])*100;echo \$percent_health."%";  ```
Is that what you were asking for?

• Thanks for the reply. It didn't quite work, the result came to:

Current HP: 74.3726235741%
I am guessing that means 74%? Does it just need to be floored or is there a way to make sure it's always a solid number with no decimals?

• Originally Posted by myfayt
Thanks for the reply. It didn't quite work, the result came to:

I am guessing that means 74%? Does it just need to be floored or is there a way to make sure it's always a solid number with no decimals?
Then round the value.
http://php.net/manual/en/function.round.php

• You can use three different things to get that to the way you want it. Using ceil or floor functions or round.

PHP Code:
``` // ceil function// this rounds everything up\$percent_health = ceil((\$user['currenthp']/\$user['maxhp'])*100);echo \$percent_health."%"; //floor function // this rounds everything down\$percent_health = floor((\$user['currenthp']/\$user['maxhp'])*100);echo \$percent_health."%";   // round// this rounds anything <5 down and anything >= 5 up\$percent_health = round((\$user['currenthp']/\$user['maxhp'])*100);echo \$percent_health."%";  ```

• My health should only be in the 70's but it's saying 100% so it isn't right. I tried round and ceil both.

PHP Code:
```  \$percent_health = ceil((\$user['currenthp']/\$user['maxhp']))*100;  ```

• That is because you have your parentheses wrong. You need to copy it like I have it. See if that works.

• Good catch! I missed that.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•