SQL Server returning a different result to a physical calculator with decimal numbers
So as part of a query I am running i need absolute accuracy (or as close as possible with computers) for the result.
When i plug this equation into SQL Server and run it:
BEGIN PRINT cast (0.99986333333333333333333333333333333333 * 9999.99 as decimal (38, 30)); END;
I get the result:
However when I plug these numbers into my physical calculator I get the result:
What i need to know is which one is right and why?
The SQL Server answer is the one Google Calculator produces and another online calculator advertised for extreme accuracy.
Can anyone show to me/ prove to me which one i should use?
One Solution collect form web for “SQL Server returning a different result to a physical calculator with decimal numbers”
I think you’ve answered your own question by stating that two other sources back up SQL Server on this.
Further, if you cast each operand, so you get exact (not floating point) math, you get the same answer:
BEGIN PRINT CAST(CAST(0.99986333333333333333333333333333333333 AS decimal(38,30)) * CAST(9999.99 AS decimal(38,30)) as decimal (38, 30)); END;
So I’d trust the SQL Server answer.