Problem with dividing two integers
#2

If you use arithmetic with different data types the "weaker" data type will be converted

Now if you divide a Float with an Integer, the Integer will be converted to a Float, resulting in a Float
But if you do a simple Integer division you get as result an integer
PHP код:
printf("%f"5.0 2.0); // float / float = float => 2.5
printf("%f"5.0 2); // float / int = float / float(int) = float => 2.5
printf("%f"2.0); // int / float = float(int) / float = float => 2.5
printf("%d"2); // int / int = int => 2 (the .5 gets chopped away) 
Reply


Messages In This Thread
Problem with dividing two integers - by vannesenn - 02.01.2016, 21:48
Re: Problem with dividing two integers - by Nero_3D - 02.01.2016, 22:01
Re: Problem with dividing two integers - by vannesenn - 02.01.2016, 22:05
Re: Problem with dividing two integers - by Nero_3D - 02.01.2016, 22:37
Re: Problem with dividing two integers - by vannesenn - 02.01.2016, 22:48
Re: Problem with dividing two integers - by Vince - 02.01.2016, 23:01
Re: Problem with dividing two integers - by vannesenn - 02.01.2016, 23:09

Forum Jump:


Users browsing this thread: 1 Guest(s)