Division between integers in Java

前端 未结 1 1713
一生所求
一生所求 2020-11-29 11:55

I need to perform division between integers in Java, and the result should be a float.

Could I just use / symbol for it? As in:

int int         


        
1条回答
  •  温柔的废话
    2020-11-29 12:20

    Cast one of the integers to float to ensure a floating point division:

    float result = integer1 / (float) integer2
    

    0 讨论(0)
提交回复
热议问题