From c885137ed7102acbfef0a471c211c50f12b97534 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Mon, 16 Sep 2019 22:47:13 -0400 Subject: [PATCH] [O] Fix floating point precision errors --- src/utils/gpa-utils.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/gpa-utils.ts b/src/utils/gpa-utils.ts index 1d16fce..ae8b48b 100644 --- a/src/utils/gpa-utils.ts +++ b/src/utils/gpa-utils.ts @@ -65,8 +65,11 @@ export class GPAUtils totalGPA += this.getGP(course); }); - // Get average GPA - return {gpa: totalGPA / courses.length, accurate: accurate}; + // Get average GPA, round to two decimal places + let gpa = Math.round(totalGPA / courses.length * 100) / 100; + + // Return results + return {gpa: gpa, accurate: accurate}; } /**