1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Added DatabaseFeatures.rounds_to_even.

This feature flag useful with MongoDB: "Rounding to the nearest even
value supports more even distribution of rounded data than always
rounding up or down."
This commit is contained in:
Tim Graham
2024-12-18 06:50:48 -05:00
committed by GitHub
parent 20f9f61805
commit bb6114ce50
3 changed files with 7 additions and 2 deletions

View File

@@ -52,7 +52,8 @@ class CastTests(TestCase):
),
).get()
self.assertEqual(float_obj.cast_f1_decimal, decimal.Decimal("-1.93"))
self.assertEqual(float_obj.cast_f2_decimal, decimal.Decimal("3.5"))
expected = "3.4" if connection.features.rounds_to_even else "3.5"
self.assertEqual(float_obj.cast_f2_decimal, decimal.Decimal(expected))
author_obj = Author.objects.annotate(
cast_alias_decimal=Cast(
"alias", models.DecimalField(max_digits=8, decimal_places=2)