| Issue 224: | Pyodbc interprets SQL_REAL to float instead of decimal | |
| 1 person starred this issue and may be notified of changes. | Back to list |
What steps will reproduce the problem? 1. Read a SQL_REAL value of .105 from any SQL database using pyodbc 2. Print the value to log or screen from python code. What is the expected output? .105 What do you see instead? .104999996722
Dec 8, 2011
Project Member
#1
mkleehammer
Status:
NoFix
Dec 8, 2011
Reading your references, SQL_Real is indeed a floating-pointing type. However, in Oracle it seems to have much more precision (I think it's 63 bits). This means that pyodbc is frequently performing a lossy conversion to a less-precise native float type. I can't change my datatype. Sometimes the database one is pulling from is used by multiple applications, and is owned and operated by people who work in a different department, and live in a different country. The workaround, for all you folks with the same problem who landed here from googlesearch, is as follows: Select cast(foo_SQL_REAL_value as String) as foo_SQL_REAL_value, .... Then parse the string to a Decimal value in native Python code.
Dec 8, 2011
You may also consider casting to a different numeric type that pyodbc will automatically cast to a Decimal. |