JaTochNietDan Posted March 2, 2009 Share Posted March 2, 2009 How would you, calculate a percentage? Like say I want there to be a 30% chance of this topic to be posted when I click post? I tried messing with rand(0,10) but I dont think that would account for percentages correctly. Is there a function? Thanks for any replies Link to comment https://forums.phpfreaks.com/topic/147638-solved-calculating-a-percentage/ Share on other sites More sharing options...
rhodesa Posted March 2, 2009 Share Posted March 2, 2009 if(rand(1,100) <= 30){ echo "30% of the time"; } p.s. - if your percentages are divisible by 10, you can use 1-10 and 3 instead Link to comment https://forums.phpfreaks.com/topic/147638-solved-calculating-a-percentage/#findComment-775032 Share on other sites More sharing options...
JaTochNietDan Posted March 2, 2009 Author Share Posted March 2, 2009 if(rand(1,100) <= 30){ echo "30% of the time"; } p.s. - if your percentages are divisible by 10, you can use 1-10 and 3 instead hmm, this makes sense thanks Link to comment https://forums.phpfreaks.com/topic/147638-solved-calculating-a-percentage/#findComment-775036 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.