Jump to content

[SOLVED] Divide By functions


jwwceo

Recommended Posts

If all the values are integers or strings containing integer values, the math is being done using integer math. When the result is 1 you get 1. When the result is < 1 you get zero.

 

As long as one of the values is a float, the math will be done using floating point math.

 

This should work, but don't quote me on that -

 

$rating=((float)$rs['up']/($rs['up']+$rs['down']));

 

Edit: This should work as well -

 

$rating= 0.0 + ($rs['up']/($rs['up']+$rs['down']));

Link to comment
Share on other sites

if you're looking for a way to put it into a visual fraction of some sort

 

like $rating = UP/TOTAL

you can just go

$rating= $rs['up'] . "/" . ($rs['up']+$rs['down']);

 

but as long as you have it the previous way.....it'll just go ahead and do the math

 

 

I get only 1's or 0's as the result.

Surely it doesn't happen every time, for debugging purposes I recommend you click the "up button" and "down button" buttons you have a few times or a hundred...just to see if it's all working

 

EDIT: nevermind sorry

you're getting that because it's always going to be a fraction....

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.