A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/ below:

$trunc (aggregation) - Database Manual

$trunc

$trunc truncates a number to a whole integer or to a specified decimal place.

The $trunc operator has the following syntax:

{ $trunc : [ <number>, <place> ] }

Field

Type

Description

<number>

number

Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long.

$trunc returns an error if the expression resolves to a non-numeric data type.

<place>

integer

Optional Can be any valid expression that resolves to an integer between -20 and 100, exclusive. For example, -20 < place < 100. Defaults to 0 if unspecified.

The <number> expression can be any valid expression as long as it resolves to a number. For more information on expressions, see Expression Operators.

$trunc does not round the truncated data. To round input values to a specified place, use the $round expression.

The returned data type matches the data type of the input expression or value.

Example

Results

{ $trunc: [ NaN, 1] }

NaN

{ $trunc: [ null, 1] }

null

{ $trunc : [ Infinity, 1 ] }

Infinity

{ $trunc : [ -Infinity, 1 ] }

-Infinity

Create a collection named samples with the following documents:

db.samples.insertMany(   [      { _id: 1, value: 19.25 },      { _id: 2, value: 28.73 },      { _id: 3, value: 34.32 },      { _id: 4, value: -45.34 }   ])

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4