Skip to content

Commit c833ff9

Browse files
committed
DOCSP-13855-mod-has-inconsistent-rounding
1 parent b5eea15 commit c833ff9

File tree

1 file changed

+59
-0
lines changed
  • source/reference/operator/query

1 file changed

+59
-0
lines changed

source/reference/operator/query/mod.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,62 @@ operator with an array that contains four elements:
117117
"$err" : "bad query: BadValue malformed mod, too many elements",
118118
"code" : 16810
119119
}
120+
121+
Floating Point Arguments
122+
~~~~~~~~~~~~~~~~~~~~~~~~
123+
124+
The ``$mod`` expression rounds decimal input towards zero.
125+
126+
The following examples demonstrate this behavior:
127+
128+
.. example::
129+
130+
Input query:
131+
132+
.. code-block:: javascript
133+
134+
db.inventory.find( { qty: { $mod: [ 4.0, 0 ] } } )
135+
136+
Results:
137+
138+
.. code-block:: javascript
139+
:copyable: false
140+
141+
{ _id: 1, item: 'abc123', qty: 0 }
142+
{ _id: 3, item: 'ijk123', qty: 12 }
143+
144+
.. example::
145+
146+
Input query:
147+
148+
.. code-block:: javascript
149+
150+
db.inventory.find( { qty: { $mod: [ 4.5, 0 ] } } )
151+
152+
Results:
153+
154+
.. code-block:: javascript
155+
:copyable: false
156+
157+
{ _id: 1, item: 'abc123', qty: 0 }
158+
{ _id: 3, item: 'ijk123', qty: 12 }
159+
160+
.. example::
161+
162+
Input query:
163+
164+
.. code-block:: javascript
165+
166+
db.inventory.find( { qty: { $mod: [ 4.99, 0 ] } } )
167+
168+
Results:
169+
170+
.. code-block:: javascript
171+
:copyable: false
172+
173+
{ _id: 1, item: 'abc123', qty: 0 }
174+
{ _id: 3, item: 'ijk123', qty: 12 }
175+
176+
Each query applies ``4`` to the $mod function regardless of
177+
decimal points, resulting in the same result set.
178+

0 commit comments

Comments
 (0)