Charles Anderson
Charles Anderson

Reputation: 21

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 the 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

Upvotes: 2

Views: 1742

Answers (3)

Adam Crume
Adam Crume

Reputation: 15834

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.

Upvotes: -2

Mark Byers
Mark Byers

Reputation: 838696

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

Upvotes: 3

Vagrant
Vagrant

Reputation: 1716

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

Upvotes: 9

Related Questions