@@ -77,28 +77,32 @@ Numeric Model
77
77
Using the Decimal BSON Type
78
78
~~~~~~~~~~~~~~~~~~~~~~~~~~~
79
79
80
- .. versionadded:: 3.4
81
-
82
- The ``decimal`` :doc:`BSON type </reference/bson-types>` uses the
83
- IEEE 754 decimal128 decimal-based floating-point numbering format.
84
- Unlike binary-based floating-point formats (i.e., the ``double`` BSON
85
- type), decimal128 does not approximate decimal values and is able to
80
+ The ``decimal128`` :ref:`BSON type <bson-types>` uses the IEEE 754
81
+ ``decimal128`` decimal-based floating-point numbering format. Unlike
82
+ binary-based floating-point formats such as the ``double`` BSON type,
83
+ ``decimal128`` does not approximate decimal values and is able to
86
84
provide the exact precision required for working with monetary data.
87
85
88
- From :binary:`~bin.mongosh` ``decimal`` values are assigned and
89
- queried using the ``NumberDecimal()`` constructor. The following
90
- example adds a document containing gas prices to a ``gasprices``
91
- collection:
86
+ In :binary:`~bin.mongosh`, ``decimal`` values are assigned and queried
87
+ using the ``Decimal128()`` constructor. The following example adds a
88
+ document containing gas prices to a ``gasprices`` collection:
92
89
93
90
.. code-block:: javascript
94
91
95
- db.gasprices.insert{ "_id" : 1, "date" : ISODate(), "price" : NumberDecimal("2.099"), "station" : "Quikstop", "grade" : "regular" }
96
-
92
+ db.gasprices.insertOne(
93
+ {
94
+ "date" : ISODate(),
95
+ "price" : Decimal128("2.099"),
96
+ "station" : "Quikstop",
97
+ "grade" : "regular"
98
+ }
99
+ )
100
+
97
101
The following query matches the document above:
98
102
99
103
.. code-block:: javascript
100
104
101
- db.gasprices.find( { price: NumberDecimal ("2.099") } )
105
+ db.gasprices.find( { price: Decimal128 ("2.099") } )
102
106
103
107
For more information on the ``decimal`` type, see
104
108
:ref:`shell-type-decimal`.
@@ -114,7 +118,7 @@ to perform the transformation as it accesses records.
114
118
115
119
Alternative to the procedure outlined below, starting in version
116
120
4.0, you can use the :expression:`$convert` and its helper
117
- :expression:`$toDecimal` operator to convert values to ``NumberDecimal ()``.
121
+ :expression:`$toDecimal` operator to convert values to ``Decimal128 ()``.
118
122
119
123
One-Time Collection Transformation
120
124
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0 commit comments