#31487: Add support for precision argument to Round
-------------------------------------+-------------------------------------
               Reporter:  Baptiste   |          Owner:  nobody
  Mispelon                           |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  3.0
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Django's `Round` function currently only supports rounding to the nearest
 integer. If you need to round to a more specific precision you need to
 roll out your own solution.

 But as far as I can tell, all backends natively supported by Django
 support a second argument to `Round`:

 * Postgres: https://www.postgresql.org/docs/12/functions-math.html
 #FUNCTIONS-MATH-FUNC-TABLE
 * Sqlite: https://sqlite.org/lang_corefunc.html#round
 * MySQL: https://dev.mysql.com/doc/refman/8.0/en/mathematical-
 functions.html#function_round
 * Oracle:
 https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions135.htm

 In my project (postgres only) my work around was to declare my own custom
 function:
 {{{#!python
 class Round(Func):
     function = 'ROUND'
     arity = 2
 }}}

 But having this built-in would be quite useful.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31487>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.3bd3b759e208a2a8fe13ca3ce10978c1%40djangoproject.com.

Reply via email to