Rineru Posted December 22, 2007 Share Posted December 22, 2007 okay first off does modulo division work in PHP like it does in javascript? Second if it does Ill be using something like this: asdf = 4.23 blah = (((asdf%1)/60)+(asdf-(asdf%1)))/10 blah = 0.40038333333333337 How can I make blah a percentage? And thirdly I won't b using a second variable (blah) so how would I go about making it into a percentage in one long string... Quote Link to comment https://forums.phpfreaks.com/topic/82794-solved-decimal-to-percentage/ Share on other sites More sharing options...
Zane Posted December 22, 2007 Share Posted December 22, 2007 yeah the modulus is the same. and to make a percentage just multiply by 100 and use round(), ceil(), or floor() to narrow the number down Quote Link to comment https://forums.phpfreaks.com/topic/82794-solved-decimal-to-percentage/#findComment-421068 Share on other sites More sharing options...
Rineru Posted December 22, 2007 Author Share Posted December 22, 2007 So the final thing would be: floor(((((asdf%1)/60)+(asdf-(asdf%1)))/10)*100) IT works in Javascript, I know it'll work in PHP Thank you, I used all my Math thinking and function lists when I was trying to think of a way to input a time as a decimal 4 mins 23 seconds 4.23 I want to be at 10 mins so I use that and I find I'm roughly 40% the way there. Quote Link to comment https://forums.phpfreaks.com/topic/82794-solved-decimal-to-percentage/#findComment-421080 Share on other sites More sharing options...
Barand Posted December 22, 2007 Share Posted December 22, 2007 As $N%1 always gives 0 (the integer remainder when divided by 1) then your code $blah = ((($asdf%1)/60)+($asdf-($asdf%1)))/10; is equivalent to $blah = $asdf/10; PS you need fmod() which gives the fractional remainder after the division $blah = ((fmod($asdf,1)/60)+($asdf-(fmod($asdf,1))))/10; Quote Link to comment https://forums.phpfreaks.com/topic/82794-solved-decimal-to-percentage/#findComment-421098 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.