Round *UP* to the nearest 100 in SQL Server

后端 未结 13 961
野性不改
野性不改 2020-12-25 11:18

Is it possible to easily round a figure up to the nearest 100 (or 1000, 500, 200 etc.) in SQL Server?

So:

720 -> 800
790 -> 800
1401 -> 1500

13条回答
  •  独厮守ぢ
    2020-12-25 11:39

    The following should work. After reading your question, I'm not exactly sure what you want 100 to return. For this 100 returns 100.

    select floor((X + 99) / 100) * 100;
    

    This gives the following results:

    0 -> 0
    1 -> 100
    99 -> 100
    100 -> 100
    101 -> 200
    

提交回复
热议问题