Why does int exp1 = 14/20*100; equals '0' in java?

后端 未结 4 1543
不知归路
不知归路 2020-12-12 07:07

I\'m trying to do some basic math and it keeps popping up as 0. I\'m sure it has to do with it being an int but I don\'t know how to work around it

4条回答
  •  一生所求
    2020-12-12 07:37

    Your result is being cast as an int, so you are losing precision.

    Try

    double exp1 = 14/20.0*100;
    

提交回复
热议问题