PYTHON-1068 - Update FAQ entry for Decimal
This commit is contained in:
parent
7933d5a95f
commit
b320f82457
14
doc/faq.rst
14
doc/faq.rst
@ -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?
|
||||
--------------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user