diff --git a/FusionIIIT/applications/examination/api/views.py b/FusionIIIT/applications/examination/api/views.py index f001de03c..3b2a2c25b 100644 --- a/FusionIIIT/applications/examination/api/views.py +++ b/FusionIIIT/applications/examination/api/views.py @@ -4695,6 +4695,15 @@ def post(self, request): ) +def _credits_text(value): + """A whole credit count prints bare; a fractional one keeps one decimal.""" + try: + number = float(value) + except (TypeError, ValueError): + return str(value) + return str(int(number)) if number == int(number) else '{:.1f}'.format(number) + + def _build_grade_validation_semesters(student): """One student's full semester-by-semester grade history for Grade Validation -- shared by GradeValidationView's get_all_grades action and export_all_zip action @@ -5136,7 +5145,7 @@ def _build_pdf_bytes(stu_info, semesters): tbl_data.append([ Paragraph(str(c["code"]), small), Paragraph(str(c["name"]), small), - Paragraph(str(c["credits"]), small), + Paragraph(_credits_text(c["credits"]), small), Paragraph(str(c["grade"]), small), Paragraph(f'{rem}', small), ]) @@ -5161,7 +5170,7 @@ def _build_pdf_bytes(stu_info, semesters): # Summary row — 4 equal columns, fills full width if is_reg: sum_row = [ - Paragraph(f"Total Registered Credits: {sem['semester_credits']}", small), + Paragraph(f"Total Registered Credits: {_credits_text(sem['semester_credits'])}", small), Paragraph("", small), Paragraph("", small), Paragraph("", small), @@ -5171,8 +5180,8 @@ def _build_pdf_bytes(stu_info, semesters): spi_str = f"{sem['spi']:.1f}" if sem.get('spi') is not None else "—" cpi_str = f"{sem['cpi']:.1f}" if sem.get('cpi') is not None else "—" sum_row = [ - Paragraph(f"Total Credits Earned: {sem['total_credits']}", small), - Paragraph(f"Semester Credits Earned: {sem['semester_credits']}", small), + Paragraph(f"Total Credits Earned: {_credits_text(sem['total_credits'])}", small), + Paragraph(f"Semester Credits Earned: {_credits_text(sem['semester_credits'])}", small), Paragraph(f"SPI: {spi_str}", small), Paragraph(f"CPI: {cpi_str}", small), ]