Skip to content

Commit

Permalink
#2004-rounding off the numbers in average
Browse files Browse the repository at this point in the history
  • Loading branch information
Brajesh Kumar authored and Brajesh Kumar committed Oct 12, 2023
1 parent 3034b9c commit 3a38701
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class EducationalMaterialComponent implements OnInit {
updateSummary() {
const summary = new Map<string, { count: number; sum: number }>();
const average = new Map<string, number>();

// Initialize summary and average maps in a single loop
for (const m of this.records) {
if (m.materialType) {
Expand All @@ -119,9 +119,9 @@ export class EducationalMaterialComponent implements OnInit {
const avgSummaryArray: string[] = [];

for (const [label, labelData] of summary.entries()) {
const avg = labelData.sum / labelData.count;
const avg = parseFloat((labelData.sum / labelData.count).toPrecision(2));
average.set(label, avg);

summaryArray.push(`${label}: ${labelData.sum}`);
avgSummaryArray.push(`${label}: ${avg}`);
}
Expand Down

0 comments on commit 3a38701

Please sign in to comment.