Ignore:
Timestamp:
27 Jan 2017, 15:53:33 (8 years ago)
Author:
Henrik Bettermann
Message:

Define and use format_float utility method.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py

    r14438 r14473  
    5656        )
    5757    table = []
     58    format_float = getUtility(IKofaUtils).format_float
    5859    for stud in result:
    5960        if not stud['studycourse'].has_key(str(level)):
     
    7172        end_level = getattr(stud['studycourse'].certificate, 'end_level', None)
    7273        if end_level and level >= end_level:
    73             cgpa = '%.2f' % (int(100*level_obj.cumulative_params[0])/100.0)
     74            cgpa = format_float(level_obj.cumulative_params[0], 2)
     75            #cgpa = '%.2f' % (int(100*level_obj.cumulative_params[0])/100.0)
    7476        else:
    75             cgpa = '%.3f' % (int(1000*level_obj.cumulative_params[0])/1000.0)
     77            cgpa = format_float(level_obj.cumulative_params[0], 3)
     78            #cgpa = '%.3f' % (int(1000*level_obj.cumulative_params[0])/1000.0)
    7679        if remark == 'FRNS':  # Faculty Requirements Not Satisfied (AAUE)
    7780            cgpa = ''
     
    8285                level_obj.gpa_params[1],
    8386                passed_params[2],
    84                 '%.3f' % (int(1000*level_obj.gpa)/1000.0),
     87                format_float(level_obj.gpa, 3),
     88                #'%.3f' % (int(1000*level_obj.gpa)/1000.0),
    8589                failed_courses,
    8690                not_taken_courses,
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r14461 r14473  
    256256    data = []
    257257    style = getSampleStyleSheet()
     258    format_float = getUtility(IKofaUtils).format_float
    258259    for level in levels_data:
    259260        level_obj = level['level']
     
    282283            element[2]*cm for element in tableheader], style=CONTENT_STYLE)
    283284        data.append(table)
    284         sgpa = '%s: %.2f' % (trans('Sessional GPA (rectified)', lang), level['sgpa'])
     285        sgpa = format_float(level['sgpa'], 2)
     286        sgpa = '%s: %s' % (trans('Sessional GPA (rectified)', lang), sgpa)
     287        #sgpa = '%s: %.2f' % (trans('Sessional GPA (rectified)', lang), level['sgpa'])
    285288        data.append(Paragraph(sgpa, style["Normal"]))
    286289    return data
     
    928931        f_label = trans(_('Cumulative GPA:'), portal_language)
    929932        f_label = Paragraph(f_label, ENTRY1_STYLE)
    930         f_text = formatted_text('%.3f (%s)' % (
    931             transcript_data[1], self.getClassFromCGPA(
    932                 transcript_data[1], student)[1]))
     933        format_float = getUtility(IKofaUtils).format_float
     934        cgpa = format_float(transcript_data[1], 3)
     935        f_text = formatted_text('%s (%s)' % (
     936            cgpa, self.getClassFromCGPA(transcript_data[1], student)[1]))
    933937        f_text = Paragraph(f_text, ENTRY1_STYLE)
    934938        contextdata.append([f_label,f_text])
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/utils.py

    r14040 r14473  
    405405            return export_disabled_message
    406406        return None
     407
     408    def format_float(self, value, prec):
     409        # cut floating point value
     410        value = int(pow(10, prec)*value) / (1.0*pow(10, prec))
     411        return '{:{width}.{prec}f}'.format(value, width=0, prec=prec)
Note: See TracChangeset for help on using the changeset viewer.