Rounding edge cases for averages

Bug #1372624 reported by Douglas Cerna
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SchoolTool Gradebook
New
Undecided
Douglas Cerna

Bug Description

We use string formatting for printing averages:

"%.1f" % average

We store grades as decimals and in some cases this produces a rounding issue:

>>> average = Decimal('6.85')
>>> '%.1f' % average
'6.8'

We need to use decimal's rounding options for this.

This applies to the section gradebook as well as the report card.

Changed in schooltool.gradebook:
assignee: nobody → Douglas Cerna (replaceafill)
Revision history for this message
Gediminas Paulauskas (menesis) wrote :

The problem is default decimal rounding setting of ROUND_HALF_EVEN (on 5 round to closest even number).

>>> print '{:.2}'.format(decimal.Decimal('6.75'))
6.8

>>> average = decimal.Decimal('6.85')

>>> print '{:.1f}'.format(average)
6.8

>>> ctx = decimal.Context(rounding=decimal.ROUND_HALF_UP)

>>> with decimal.localcontext(ctx):
    print '{:.1f}'.format(average)
...
6.9

Read https://docs.python.org/2/library/decimal.html

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.