Skip to content

Commit

Permalink
Revert changes to return decimal numbers when the numeric precision w…
Browse files Browse the repository at this point in the history
…as too

great to be returned accurately as a floating point number. This change had too
great an impact on existing functionality and an output type handler can be
used to return decimal numbers where that is desirable
(#279).
  • Loading branch information
anthony-tuininga committed Mar 12, 2019
1 parent 8789c6d commit c112af3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/cxoTransform.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,12 @@ PyObject *cxoTransform_toPython(cxoTransformNum transformNum,
#endif
Py_DECREF(stringObj);
return result;
} else if (transformNum != CXO_TRANSFORM_DECIMAL &&
bytes->length <= 15) {
} else if (transformNum == CXO_TRANSFORM_DECIMAL) {
result = PyObject_CallFunctionObjArgs(
(PyObject*) cxoPyTypeDecimal, stringObj, NULL);
} else {
result = PyNumber_Float(stringObj);
Py_DECREF(stringObj);
return result;
}
result = PyObject_CallFunctionObjArgs(
(PyObject*) cxoPyTypeDecimal, stringObj, NULL);
Py_DECREF(stringObj);
return result;
case CXO_TRANSFORM_OBJECT:
Expand Down
6 changes: 3 additions & 3 deletions test/NumberVar.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def testAcceptableBoundaryNumbers(self):
decimal.Decimal("-9.99999999999999e+125"), 0.0, 1e-130,
-1e-130]
outValues = [int("9" * 15 + "0" * 111), -int("9" * 15 + "0" * 111),
0, decimal.Decimal("1e-130"), decimal.Decimal("-1e-130")]
0, 1e-130, -1e-130]
for inValue, outValue in zip(inValues, outValues):
self.cursor.execute("select :1 from dual", (inValue,))
result, = self.cursor.fetchone()
Expand Down Expand Up @@ -351,8 +351,8 @@ def testReturnFloatFromDivision(self):
from TestNumbers
where IntCol = 1""")
result, = self.cursor.fetchone()
self.assertAlmostEqual(result,
decimal.Decimal("1") / decimal.Decimal("7"))
self.assertEqual(result, 1.0 / 7.0)
self.assertTrue(isinstance(result, float), "float not returned")

def testStringFormat(self):
"test that string format is returned properly"
Expand Down

0 comments on commit c112af3

Please sign in to comment.