I am looking for any documentation on the decimal precision in Postgres and Excel.

I have a database which was imported through excel. I am finding that the SUM() result in excel is slightly different than the SUM() method in Postgres (usually at the 3rd or 4th decimal place depending on what i include or exclude from the data. I am curious to see if this is because of a floating point precision issue, or if there may be some small differences resulting from the import.

有帮助吗?

解决方案

You find documentation for Postgres in the manual.

PostgreSQL's decimal is not a floating point number, but an arbitrary precision number. Additions like sum() are exact in Postgres.

The types decimal and numeric are equivalent. Both types are part of the SQL standard.

In contrast, MS Excel operates with limited accuracy. Quoting Wikipedia at the site @Tim provided:

As with other spreadsheets, Microsoft Excel works only to limited accuracy because it retains only a certain number of figures to describe numbers (it has limited precision)

Discrepancies are to be expected. You might try PostgreSQL's double precision type, which seems a better match. I doubt, you'll get a 100% match, though.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top