Division returns zero

前端 未结 6 1380
[愿得一人]
[愿得一人] 2020-11-22 04:19

This simple calculation is returning zero, I can\'t figure it out:

decimal share = (18 / 58) * 100;
6条回答
  •  一生所求
    2020-11-22 05:05

    18 / 58 is an integer division, which results in 0.

    If you want decimal division, you need to use decimal literals:

    decimal share = (18m / 58m) * 100m;
    

提交回复
热议问题