C# how to always round down to nearest 50

后端 未结 3 1805
时光取名叫无心
时光取名叫无心 2020-12-17 14:58

I\'ve done a search on C# rounding, but haven\'t been able to find the answer to my current problem.

What I want to do is always round down to the nearest 50. All th

3条回答
  •  攒了一身酷
    2020-12-17 15:51

    Divide the value by 50, round down to the closest whole number, and multiply by 50 again:

    double n = Math.Floor(n / 50.0) * 50.0;
    

提交回复
热议问题