Weird rounding with float values #728
Unanswered
mergeninja
asked this question in
Q&A
Replies: 1 comment
-
I'll throw some more head scratching at you. On my laptop the returned value is the one you expect: # Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
>>> import psycopg
>>> conn = psycopg.connect()
>>> conn.execute("select 180.07117437722425::float8").fetchone()[0]
180.07117437722425 Tested with both C and Python implementation. So, the question is what platform and Python version are you using? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I've been scratching my head about this for a while and hours googling hasn't helped. I've got a table in a postgres database with a float8 column in it. If I query said table from pycharm using the jdbc driver I can see the value it contains:
If I perform the same query using python + psycopg I get the number
180.071174377224
- note it's rounded it to fit in 16 characters (the final two digits25
are missing).If I perform the same query again using psql I also get the 16 character result:
180.071174377224
Clearly the database has the value
180.07117437722425
, which is the precision I would like, but I'm really not sure why there seems to be this 16 character limit on the output in psycopg and psql. I've confirmed it's 16 characters because if I take 100 off the value I start seeing80.0711743772243
, which is also 16 characters, with the finial digit rounded from 2 to 3 due to it actually being80.xxxx425
.Does anyone know of any way I can remove this character limit?
Many thanks
Beta Was this translation helpful? Give feedback.
All reactions