Jump to content

No Floating Numbers After Division


mobone

Recommended Posts

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

I think php refers to them as doubles and not floats, as JavaScript does.

Link to comment
Share on other sites

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

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

Archived

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

×
×
  • Create New...