How to make the division of 2 ints produce a float instead of another int?

后端 未结 9 1124
天命终不由人
天命终不由人 2020-11-22 08:24

In another Bruce Eckels exercise in calculating velocity, v = s / t where s and t are integers. How do I make it so the division cranks out a float?

         


        
9条回答
  •  醉梦人生
    2020-11-22 08:49

    You can cast even just one of them, but for consistency you may want to explicitly cast both so something like v = (float)s / (float)t should work.

提交回复
热议问题