Q
Problem solve Get help with specific problems with your technologies, process and projects.

Rounding numbers

Rounding problems. Is this a SQL server bug?
Examples:
 1) SELECT round(0.144999999999, 2) GO Result: -------------- .140000000000 (1 row(s) affected) 2) SELECT round(round(0.144999999999, 3 ),2) go Result: -------------- .150000000000 (1 row(s) affected)
Thanks.

Nope, that is expected behavior. SQL Server will retain all decimal places upon rounding off numbers. In the first case, you are rounding off .144 to two decimal places. The second 4 rounds down and the remainder of the digits are essentially turned into zeros. In the second case, you are rounding .1449 to three digits. This produces .145 which you then round to 2 places giving you .15 and the rest of the digits are zeroed out and retained. There should be a very technical discussion of rounding locted in books online that explains this in much more detail.

 

For More Information

This was last published in April 2002

Dig Deeper on Microsoft SQL Server Installation

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchDataCenter

SearchDataManagement

SearchAWS

SearchOracle

SearchContentManagement

SearchWindowsServer

Close