High Precision Multiplication


Whenever large numbers are multiplied in SQL Server, a loss of precision may occur. I am working with a database that makes extensive usage of the type DECIMAL(38, 18) to hold large numbers. When multiplying two numbers, precision is loss in most cases because SQL Server internally truncates the numbers prior to multiplying them. This can often be frustrating, like in the following example:

DECLARE @d1 DECIMAL(38, 18) = 1234.123456789012345678, @d2 DECIMAL(38, 18) = 1.0 SELECT CONVERT(DECIMAL(38, 18), @d1 * @d2)

The expected result is obviously 1234.123456789012345678, but SQL Server displays 1234.123457000000000000. While we all agree that multiplying large numbers