By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,379 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,379 IT Pros & Developers. It's quick & easy.

Rounding not working

P: n/a
When I

SELECT CAST(96.58 AS DECIMAL(10 , 0)), it returns 97.

When I

SELECT CAST(575629 / 54 AS DECIMAL(10 , 0)), why it returns 10659? It
should return 10660, right?

What am I missing?

Thanks,

Faye Larson
Mar 25 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Running this will explain it:

SELECT 575629 / 54

When integer dividend is divided by an integer divisor the result is an
integer that has any fractional part of the result truncated, so you get
10659.

But try this:
SELECT CAST(575629 / 54.0 AS DECIMAL(10 , 0))

or

SELECT CAST(1.0 * 575629 / 54 AS DECIMAL(10 , 0))

Those will give you the expected result 10660, because the higher precedence
argument data type is the resulting data type of the division.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Mar 25 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.