Rounding edge cases for averages
Bug #1372624 reported by
Douglas Cerna
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) |
To post a comment you must log in.
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): '.format( average)
print '{:.1f}
...
6.9
Read https:/ /docs.python. org/2/library/ decimal. html