0

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.

Eric Brown
  • 13,774
  • 7
  • 30
  • 71
tomy
  • 3
  • 2

1 Answers1

0

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.

mgalloy
  • 2,356
  • 1
  • 12
  • 10