Question

I am trying to write something like

ep = 23 + (26/60)

and this will give me ep=23; however, if I change either of the 26 or 60 to 26. or 26.d, ep=23.43 which is what I want.

I am just curious about why is it like this? I try some searching, but the question is difficult to express.

Était-ce utile?

La solution

The result type of an operation is given by the types of the arguments. So above, in 23/60, the result should be 0 using integer division. But, if one of 23 or 60 is a float (specified by making them 23. or 60., respectively), then the operation will be done as float division. Furthermore, setting one of them as a double makes the operation be done in double precision.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top