PHP - Php Percent
Hi,
Example: echo percent(5, 10, 2)."%"; gives you 50% Instead of this representation, I want to use a bar like this: So what ever percentage it is, it will show on the bar. (out of 100%) anyone help me achieve this please? Thanks Code: [Select] function percent($sub, $total, $dec) { if ($sub) { $perc = $sub / $total * 100; $perc = round($perc, $dec); return $perc; } else return 0; } Similar TutorialsHey, I have a question about doing a % in PHP.. So say a user in my database has a cash amount of $20.00. Their referrer is going to get 20% of that. How would I calculate that in PHP? Stupid Question, and it might even be as simple as adding a zero, but I cannot figure it out.
$prob = number_format(mt_rand(1,100)/100, 2) ; $q = $db->query("SELECT * FROM rpg_monsters WHERE monster_zone = 1 AND chance >= $prob ORDER BY chance,rand() LIMIT 1");As you can see this works out perfectly. But only one issue. I want that 0.05 to be in the thousandths of percent: 0.005%. So it's a higher probability. But if I change it to 0.005, it never shows, even with iterations over 5000 in a for loop? I feel like I need to do something with my mt_rand? I need to simply move a decimal over someplace, but not sure where. Edited by Monkuar, 12 October 2014 - 08:30 PM. Hi. I am brand new here... I have a script where I'm trying to parse an email and everything is working fine but it looks like the percent sign (%) is getting stripped out of my message. The percent sign is in the subject message and it gets removed and I also can't use it in any other strings in the script. I've tried just adding a slash in front like \% but that didn't fix it. Is there another way to escape a percent sign when using it in a script? Any help is appreciated. Thanks. -Jeff |