mobone Posted June 16, 2009 Share Posted June 16, 2009 I need the win to loss ratio, but its not returning anything after the decimal. I'm sure its an easy solution but I can't seem to figure it out.Battles won and battles lost are both integers. settype($battles_won, "float"); settype($battles_lost, "float"); settype($winloss, "float"); $winloss = $battles_lost/$battles_won; I've tried rounding the division also. Link to comment Share on other sites More sharing options...
chibineku Posted June 16, 2009 Share Posted June 16, 2009 I think php refers to them as doubles and not floats, as JavaScript does. Link to comment Share on other sites More sharing options...
mobone Posted June 16, 2009 Author Share Posted June 16, 2009 I think php refers to them as doubles and not floats, as JavaScript does.Settype syntax:"float" (only possible since PHP 4.2.0, for older versions use the deprecated variant "double")And I'm using php 5, thanks though! Link to comment Share on other sites More sharing options...
justsomeguy Posted June 16, 2009 Share Posted June 16, 2009 Have you printed out the variables to see what values they contain? Are you sure they're even floats? Link to comment Share on other sites More sharing options...
mobone Posted June 17, 2009 Author Share Posted June 17, 2009 Have you printed out the variables to see what values they contain? Are you sure they're even floats?The variables are not floats, they're ints, but I thought the settype would change them to floats. Link to comment Share on other sites More sharing options...
Ingolme Posted June 17, 2009 Share Posted June 17, 2009 I'd use the floatval() function: $winloss = floatval($battles_lost)/floatval($battles_won); Link to comment Share on other sites More sharing options...
justsomeguy Posted June 17, 2009 Share Posted June 17, 2009 The variables are not floats, they're ints, but I thought the settype would change them to floats.It will, but they're still going to have their integer values. Converting an int to a float is going to result in the same value. If you convert 8 to a float, you'll get 8.0.var_dump($battles_lost);var_dump($battles_won);$winloss = $battles_lost/$battles_won;var_dump($winloss); Link to comment Share on other sites More sharing options...
mobone Posted June 17, 2009 Author Share Posted June 17, 2009 doh! my mysql variable was an int. Wouldn't of happened if I wasn't using phpmyadmin... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.