cloudll Posted November 23, 2014 Share Posted November 23, 2014 I have made a 'health bar' for a simple browser game i have been working on. I want to use a background image to fill the health bar, so if for example, the player had full health, the health bar image width would be 100% is it possible to say set, the characters max health and the characters actual health and work it out as a percentage so i can stretch the image width as far as it needs to go? sorry if i haven't been too clear, my understanding of maths is not so good. Thanks for any tips. Quote Link to comment Share on other sites More sharing options...
cloudll Posted November 23, 2014 Author Share Posted November 23, 2014 edit: so i have this working now$current_health=250;$max_health=9999;$health_percentage=$current_health/$max_health*100;that works but returns the percentage with lots of decimals. is there a way to round the result up? Quote Link to comment Share on other sites More sharing options...
Barand Posted November 23, 2014 Share Posted November 23, 2014 either of these echo number_format($health_percentage, 2); // 2.50 printf('%0.2f', $health_percentage); // 2.50 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.