How to prevent division by zero?

后端 未结 2 1963
被撕碎了的回忆
被撕碎了的回忆 2021-02-15 14:31
ads = ads.Where(x => (x.Amount - x.Price) / (x.Amount / 100) >= filter.Persent);

if x.Amount == 0 I have error \"Divide by zero error encountered

2条回答
  •  有刺的猬
    2021-02-15 15:29

    ads = ads.Where(x => x.Amount != 0 &&
                        (x.Amount - x.Price) / (x.Amount / 100) >= filter.Persent);
    

提交回复
热议问题