Эх сурвалжийг харах

补充浮点的精度操作

Michael Wang 4 жил өмнө
parent
commit
d1be2365d5

+ 9 - 3
src/features/mark/MarkBoardKeyBoard.vue

@@ -91,16 +91,22 @@ export default defineComponent({
       const question = store.currentQuestion;
       if (!question) return [];
 
-      const remainScore = question.maxScore - (question.score || 0);
+      const remainScore = Math.round(
+        question.maxScore * 100 - (question.score || 0) * 100
+      );
       const steps = [];
       for (
         let i = 0;
         i <= remainScore;
-        i = (i * 10 + question.intervalScore * 10) / 10
+        i = Math.round(i * 100 + question.intervalScore * 100) / 100
       ) {
         steps.push(i);
       }
-      if ((remainScore * 10) % (question.intervalScore * 10) !== 0) {
+      if (
+        Math.round(remainScore * 100) %
+          Math.round(question.intervalScore * 100) !==
+        0
+      ) {
         steps.push(remainScore);
       }
 

+ 2 - 1
src/features/mark/MarkBoardMouse.vue

@@ -40,7 +40,8 @@
             </div>
             <div class="tw-flex tw-flex-wrap tw-gap-1">
               <div
-                v-for="(s, i) in question.maxScore + 1"
+                v-for="(s, i) in Math.round(question.maxScore * 100 + 100) /
+                100"
                 :key="i"
                 @click="chooseScore(question, s - 1)"
                 class="single-score"

+ 8 - 5
src/features/mark/MarkBody.vue

@@ -337,13 +337,16 @@ export default defineComponent({
       }
       // 是否保留当前的轨迹分
       const ifKeepScore =
-        (store.currentQuestion.maxScore * 10 -
-          (store.currentQuestion.score || 0) * 10 -
-          store.currentScore * 2 * 10) /
-        10;
+        Math.round(
+          store.currentQuestion.maxScore * 100 -
+            (store.currentQuestion.score || 0) * 100 -
+            store.currentScore * 2 * 100
+        ) / 100;
       if (
         (ifKeepScore < 0 && store.currentScore > 0) ||
-        (ifKeepScore * 10) % (store.currentQuestion.intervalScore * 10) !== 0
+        Math.round(ifKeepScore * 100) %
+          Math.round(store.currentQuestion.intervalScore * 100) !==
+          0
       ) {
         store.currentScore = undefined;
       }