79212384

Date: 2024-11-21 17:49:20
Score: 1.5
Natty:
Report link

You could use the modulus operator to find the remainder, and then use the remainder to round up or down to the closest .25.

To round down, simply take the original value and subtract the remainder.

To round up, if the remainder is 0 keep the original value. Otherwise, take the rounding amount (.25 in this case) and subtract the remainder from it. Add that result to the original value.

SELECT @value AS OriginalValue ,(@value % @RoundingAmount) AS Remainder ,@RoundingAmount AS RoundingAmount ,@RoundingAmount - (@value % @RoundingAmount) AS RoundingAmountMinusRemainder ,@value - (@value % @RoundingAmount) AS RoundDown ,@value + (IIF((@value % @RoundingAmount) = 0, 0, @RoundingAmount - (@value % @RoundingAmount))) AS RoundUp

Query Results

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • User mentioned (1): @value
  • User mentioned (0): @RoundingAmount
  • User mentioned (0): @RoundingAmount
  • User mentioned (0): @RoundingAmount
  • User mentioned (0): @RoundingAmount
  • User mentioned (0): @RoundingAmount
  • User mentioned (0): @RoundingAmount
  • Low reputation (0.5):
Posted by: TLaV