C# how to always round down to nearest 50

后端 未结 3 1795
时光取名叫无心
时光取名叫无心 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:37

    Another way to Guffa's:

    (((int) value) / 50) * 50
    
    0 讨论(0)
  • 2020-12-17 15:37

    Using modulus:

    var roundedDownToClosestFifty = value - (value % 50);
    
    0 讨论(0)
  • 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;
    
    0 讨论(0)
提交回复
热议问题