Tuesday 15 February 2011

floating - How do I get a float value when dividing two integers? (PHP) -


Hi, I am trying to divide two integers: 12/13 but I do not always get a full number 1 decimal number.

I have tried to cast values ​​to float before hand with success.

Actually I want to have decimal decimal result like: 0.923 ...

  $ x = 12; $ Y = 13; Echo $ value = $ x / $ y; // 0.923 no 1    

  resonance $ value = $ would like to see x / (Float) $ y;   

If you float the variable $ y , then the interpreter should use the floating point division instead of the integer division.

Because it is the default espionation to use the integer division on two integer variables.

If you used $ y = 13.0 (a float variable as a divisor) then it was different: the result is always a float number < / Div>

No comments:

Post a Comment