PYTHON-1068 - Update FAQ entry for Decimal

This commit is contained in:
Bernie Hackett 2016-05-25 18:21:53 -07:00 committed by Bernie Hackett
parent 7933d5a95f
commit b320f82457
2 changed files with 13 additions and 5 deletions

View File

@ -283,11 +283,15 @@ timeouts can be turned off entirely. Pass ``no_cursor_timeout=True`` to
How can I store :mod:`decimal.Decimal` instances?
-------------------------------------------------
MongoDB only supports IEEE 754 floating points - the same as the
Python float type. The only way PyMongo could store Decimal instances
would be to convert them to this standard, so you'd really only be
storing floats anyway - we force users to do this conversion
explicitly so that they are aware that it is happening.
PyMongo >= 3.4 supports the Decimal128 BSON type introduced in MongoDB 3.4.
See :mod:`~bson.decimal128` for more information.
MongoDB <= 3.2 only supports IEEE 754 floating points - the same as the
Python float type. The only way PyMongo could store Decimal instances to
these versions of MongoDB would be to convert them to this standard, so
you'd really only be storing floats anyway - we force users to do this
conversion explicitly so that they are aware that it is happening.
I'm saving ``9.99`` but when I query my document contains ``9.9900000000000002`` - what's going on here?
--------------------------------------------------------------------------------------------------------

View File

@ -35,6 +35,10 @@ from test import client_context, unittest
class TestDecimal128(unittest.TestCase):
def test_round_trip(self):
if not client_context.version.at_least(3, 3, 6):
raise unittest.SkipTest(
'Round trip test requires MongoDB >= 3.3.6')
coll = client_context.client.pymongo_test.test
coll.drop()