From 050762fcc921b0b398860fdabaee9f863dbcef68 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 19:20:41 +0000 Subject: [PATCH] Round fractional absence counts on absence tracking page Counts like 9.600000000000001 showed raw float sums; display them with at most one decimal. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012GTictnqhUF9xceB6t8spc --- client/src/pivots/AbsenceTrackingList.jsx | 17 +++++++++-------- client/src/utils/absenceTracking.js | 3 +++ client/src/utils/absenceTracking.test.js | 10 ++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/client/src/pivots/AbsenceTrackingList.jsx b/client/src/pivots/AbsenceTrackingList.jsx index e355e5f1..ac3eceba 100644 --- a/client/src/pivots/AbsenceTrackingList.jsx +++ b/client/src/pivots/AbsenceTrackingList.jsx @@ -29,6 +29,7 @@ import { MAX_PAGE_SIZE } from '@shared/config/settings'; import { DEFAULT_THRESHOLD_PERCENT, NEAR_THRESHOLD_ABSENCES, + formatNumber, formatPercent, getDetailDateRange, getLessonHeaders, @@ -162,7 +163,7 @@ const SummaryTiles = ({ students, noReportsCount, thresholdPercent, status, onSt { label: 'אחוז חיסור כללי', value: lessons ? formatPercent(unapproved / lessons) : '–', - hint: `${unapproved} חיסורים לא מאושרים · ${approved} מאושרים`, + hint: `${formatNumber(unapproved)} חיסורים לא מאושרים · ${formatNumber(approved)} מאושרים`, }, ]; return ( @@ -199,8 +200,8 @@ const SummaryTiles = ({ students, noReportsCount, thresholdPercent, status, onSt }; const leftText = ({ key, left }) => { - if (key === 'over') return left === 0 ? 'הגיעה לסף' : `${-left} מעל הסף`; - return left === 1 ? 'עוד חיסור אחד לסף' : `עוד ${left} חיסורים לסף`; + if (key === 'over') return left === 0 ? 'הגיעה לסף' : `${formatNumber(-left)} מעל הסף`; + return left === 1 ? 'עוד חיסור אחד לסף' : `עוד ${formatNumber(left)} חיסורים לסף`; }; const ThresholdMeter = ({ student, thresholdRatio }) => { @@ -246,7 +247,7 @@ const SubjectChips = ({ subjects }) => { key={subject.key} sx={{ ...chipSx, ...(index === 0 && subject.abs >= 3 && { borderColor: 'transparent', ...STATUS_STYLES.over.pill, fontWeight: 600 }) }} > - {subject.name} {subject.abs} + {subject.name} {formatNumber(subject.abs)} ))} {subjects.length > 4 && ( @@ -311,8 +312,8 @@ const StudentDetail = ({ student, lessonHeaders }) => { {subjects.map((subject) => ( {subject.name} - {subject.lessons} - {subject.abs} + {formatNumber(subject.lessons)} + {formatNumber(subject.abs)} {formatPercent(subject.ratio)} ))} @@ -326,7 +327,7 @@ const StudentDetail = ({ student, lessonHeaders }) => { {absences.slice(0, 10).map((absence) => ( - {formatDate(absence.date)} · {absence.subject}{absence.count > 1 ? ` (${absence.count})` : ''} + {formatDate(absence.date)} · {absence.subject}{absence.count > 1 ? ` (${formatNumber(absence.count)})` : ''} ))} @@ -373,7 +374,7 @@ const StudentRow = ({ student, thresholdRatio, lessonHeaders, open, onToggle }) {student.name} - {student.unapproved} לא מאושרים מתוך {student.lessons} שיעורים{student.approved ? ` · ${student.approved} מאושרים` : ''} + {formatNumber(student.unapproved)} לא מאושרים מתוך {formatNumber(student.lessons)} שיעורים{student.approved ? ` · ${formatNumber(student.approved)} מאושרים` : ''} diff --git a/client/src/utils/absenceTracking.js b/client/src/utils/absenceTracking.js index d8b9cd12..2bc87bdb 100644 --- a/client/src/utils/absenceTracking.js +++ b/client/src/utils/absenceTracking.js @@ -150,3 +150,6 @@ export function getDetailDateRange(extra = {}, reportMonth) { } export const formatPercent = (ratio) => `${(ratio * 100).toFixed(1)}%`; + +// Absence counts can be fractional; show at most one decimal and hide float noise (9.600000000000001). +export const formatNumber = (value) => String(Math.round((Number(value) || 0) * 10) / 10); diff --git a/client/src/utils/absenceTracking.test.js b/client/src/utils/absenceTracking.test.js index fcaf297f..5ddb89d5 100644 --- a/client/src/utils/absenceTracking.test.js +++ b/client/src/utils/absenceTracking.test.js @@ -1,4 +1,5 @@ import { + formatNumber, getDetailDateRange, getLessonHeaders, getStudentStats, @@ -123,3 +124,12 @@ describe('getDetailDateRange', () => { expect(getDetailDateRange({}, undefined)).toEqual({ from: undefined, to: undefined }); }); }); + +describe('formatNumber', () => { + it('rounds to one decimal and hides float noise', () => { + expect(formatNumber(9.600000000000001)).toBe('9.6'); + expect(formatNumber(8.899999999999999)).toBe('8.9'); + expect(formatNumber(20)).toBe('20'); + expect(formatNumber(2.25)).toBe('2.3'); + }); +});