SQL Server Large scale decimal computation in SQL

nhjlsmyf  于 2023-05-21  发布在  其他
关注(0)|答案(3)|浏览(124)

I've got stuck on some mathematical action that I perform in SQL Server 2016 Enterprise.

I need to calculate this expression:

(4.384 / 4.2989 * 100) * 98.8251017928029 / 100

In SQL I get the result 100.78141988869389772850690000

But when I calculate this expression in MS Excel, I get: 100.7814199585120000

Since these results is a Consumer Price index, the numbers after the decimal point do matter.

So, my question is, which result is correct? SQL Server or Excel.

PS. I have updated my question. Here is dbfiddle

Thank you.

uqxowvwt

uqxowvwt1#

I found same problem here: Wrong calculation in SQL-Server I've also tried the calculation with java, and it shows the result of the excel is more accurate. You should use decimal in calculation using sql.

fumotvh3

fumotvh32#

Actualy, creating DbFiddle I found errors in cast. So when errors was fixed the result now the are almost the same as in excel. There is small difference in results but the difference is behind my needs of scale

70gysomp

70gysomp3#

SELECT (CONVERT(FLOAT,4.384) / CONVERT(FLOAT,4.2989) * CONVERT(FLOAT,100)) * CONVERT(FLOAT,98.8251017928029) / CONVERT(FLOAT,100)

相关问题