summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2021-03-24 22:29:33 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-03-29 09:43:08 +0200
commit2f13c476abe4ba787b6cb71131818341911f43cc (patch)
tree444e1f2af12c8927f7e01db3f488998b0f305a8c /docs
parent61d5e57353bb811df7b5457a1856baee31299429 (diff)
Fixed #31487 -- Added precision argument to Round().
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/database-functions.txt15
-rw-r--r--docs/releases/4.0.txt4
2 files changed, 14 insertions, 5 deletions
diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt
index b63b4cff4a..ac0c5ea4ec 100644
--- a/docs/ref/models/database-functions.txt
+++ b/docs/ref/models/database-functions.txt
@@ -1147,18 +1147,19 @@ Returns a random value in the range ``0.0 ≤ x < 1.0``.
``Round``
---------
-.. class:: Round(expression, **extra)
+.. class:: Round(expression, precision=0, **extra)
-Rounds a numeric field or expression to the nearest integer. Whether half
+Rounds a numeric field or expression to ``precision`` (must be an integer)
+decimal places. By default, it rounds to the nearest integer. Whether half
values are rounded up or down depends on the database.
Usage example::
>>> from django.db.models.functions import Round
- >>> Vector.objects.create(x=5.4, y=-2.3)
- >>> vector = Vector.objects.annotate(x_r=Round('x'), y_r=Round('y')).get()
+ >>> Vector.objects.create(x=5.4, y=-2.37)
+ >>> vector = Vector.objects.annotate(x_r=Round('x'), y_r=Round('y', precision=1)).get()
>>> vector.x_r, vector.y_r
- (5.0, -2.0)
+ (5.0, -2.4)
It can also be registered as a transform. For example::
@@ -1168,6 +1169,10 @@ It can also be registered as a transform. For example::
>>> # Get vectors whose round() is less than 20
>>> vectors = Vector.objects.filter(x__round__lt=20, y__round__lt=20)
+.. versionchanged:: 4.0
+
+ The ``precision`` argument was added.
+
``Sign``
--------
diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt
index f47b2fb5a0..d84e029ccd 100644
--- a/docs/releases/4.0.txt
+++ b/docs/releases/4.0.txt
@@ -222,6 +222,10 @@ Models
whether the queryset contains the given object. This tries to perform the
query in the simplest and fastest way possible.
+* The new ``precision`` argument of the
+ :class:`Round() <django.db.models.functions.Round>` database function allows
+ specifying the number of decimal places after rounding.
+
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~