Jump to content

[SOLVED] Decimal to percentage


Rineru

Recommended Posts

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...

Link to comment
https://forums.phpfreaks.com/topic/82794-solved-decimal-to-percentage/
Share on other sites

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.

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.