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']));

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

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.