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