开发者

I am looking for a way to round the decimal portion of numbers up or down to the nearest .25, .5, .75, or whole number

If th开发者_StackOverflow社区e decimal part is 0.1 to 0.12, it rounds down to the next lower integer If the decimal part is 0.13 to 0.37 it rounds to 0.25 If the decimal part is 0.38 to 0.62 it rounds to 0.5 If the decimal part is 0.63 to 0.87 it rounds to 0.75 If the decimal part is 0.88 or more, it rounds up to the next higher integer


Multiply by 4, round to the nearest integer, divide by 4?


There is a general method for this:

  • Multiply your number by 4.
  • Round to the nearest integer.
  • Divide by 4.

In SQL:

ROUND(column * 4) / 4


I don't know the exact function name, but basically you use floor(4*x)/4. floor might be called int, to_int, or something like that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜