1

I'm on SQL Server 2005, and I am trying to figure out a rounding issue with smallmoney data types.

For example, the value 1.2849, when rounded to 2 decimal places, produces 1.28, but shouldn't it produce 1.29? e.g. 9 rounds up for 1.285, 5 rounds up for 1.29.

Here is the example:

SELECT
    'CAST(1.2849 AS SMALLMONEY)' OPERATION, CAST(1.284948 AS SMALLMONEY) RESULT
UNION
SELECT
    'ROUND(CAST(1.2849 AS SMALLMONEY), 2)', ROUND(CAST(1.284948 AS SMALLMONEY), 2)
UNION
SELECT
    'ROUND(ROUND(CAST(1.2849 AS SMALLMONEY), 3), 2)', ROUND(ROUND(CAST(1.2849 AS SMALLMONEY), 3), 2)

1 Answer 1

4

I am fairly certain that it just looks at the third decimal digit... and that's 4 so it rounds down to 1.28.

Clarify - it looks to the digit one greater than what you are rounding to... so it looks to the third because you are rounding to the second.

4
  • 2
    I concur. The laws of math make it clear that rounding in this instance should go down, not up.
    – jcolebrand
    Mar 22, 2012 at 16:00
  • Got it... so you are saying that it is behaving in a mathematically correct way, right?
    – GWR
    Mar 22, 2012 at 16:01
  • Yep. It's mathematically correct!
    – JHFB
    Mar 22, 2012 at 16:05
  • @cbwdev: Yes, it's closer to 1.28 than to 1.29 Mar 22, 2012 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.