Problem with dividing two integers
#3

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
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) 
Wait, but I got 0.00 instead 2. And why I can't 5 print like 5.00? I don't remember I can't do like that before.

It Works with this code

Код:
printf("%.2f", float(5) / float(2));
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)