浏览代码

Fix decimal parsing for numbers with .0 ending

Lucas de Souza 3 年之前
父节点
当前提交
990e4742ee
共有 1 个文件被更改,包括 9 次插入1 次删除
  1. 9 1
      js/util/parseFromVisual.js

+ 9 - 1
js/util/parseFromVisual.js

@@ -1,5 +1,6 @@
 import { IVProgParser } from "../ast/ivprogParser";
 import * as Expressions from "../ast/expressions";
+import { Types } from "../typeSystem/types";
 
 const TYPES = {
   VARIABLE: "var",
@@ -102,7 +103,14 @@ function expressionWalker (expression) {
   } else {
     let value = expression.value;
     if (expression.value.toNumber) {
-      value = expression.value.toNumber();
+      if (
+        Types.REAL.isCompatible(expression.type) &&
+        expression.value.decimalPlaces() == 0
+      ) {
+        value = expression.value.toFixed(2);
+      } else {
+        value = expression.value.toNumber();
+      }
     }
     result = [
       {