Re: Inconsistent results for division and multiplication operations
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Erik Brandsberg <erik@heimdalldata.com>
Cc: szy <598546998@qq.com>, pgsql-sql <pgsql-sql@lists.postgresql.org>
Date: 2024-11-25T16:34:38Z
Lists: pgsql-sql
Erik Brandsberg <erik@heimdalldata.com> writes: > This is a common issue with using floating point math. You will see the > same issue with many systems. Basically, the order of operations can > trigger very minor differences in results, but if you round the first > result to the same number of significant digits as the input, it would be > identical. > https://learn.microsoft.com/en-us/office/troubleshoot/access/floating-calculations-info Yeah. The OP is actually working with PG's "numeric" type, not floating-point, but the principle is the same. Some division results can't be represented exactly in any finite number of digits, so you get roundoff error. regards, tom lane