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

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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