diff --git a/src/expressions/expressions.ts b/src/expressions/expressions.ts index 89f91b323b..c1f2304e44 100644 --- a/src/expressions/expressions.ts +++ b/src/expressions/expressions.ts @@ -264,7 +264,7 @@ export class Const extends Operand { return value.substring(1, value.length - 1); if (OperandMaker.isNumeric(value)) { if (value.indexOf("0x") == 0) return parseInt(value); - if (value.length > 1 && value[0] == "0") return value; + if (value.length > 1 && value[0] == "0" && (value.length < 2 || (value[1] !== "." && value[1] !== ","))) return value; return parseFloat(value); } return value; diff --git a/src/helpers.ts b/src/helpers.ts index aaaed4057d..aff744b312 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -342,6 +342,7 @@ export class Helpers { } return a + b; } + if(typeof a === "string" || typeof b === "string") return a + b; return Helpers.correctAfterPlusMinis(a, b, a + b); } public static correctAfterMultiple(a: number, b: number, res: number): number { diff --git a/tests/expressions/expressionParserTest.ts b/tests/expressions/expressionParserTest.ts index 3b4a45847a..62684452a8 100644 --- a/tests/expressions/expressionParserTest.ts +++ b/tests/expressions/expressionParserTest.ts @@ -1450,4 +1450,9 @@ QUnit.test("year, month, day, weekday", function(assert) { assert.deepEqual(runner.run({}), new Date().getDate(), "current day"); runner = new ExpressionRunner("weekday()"); assert.deepEqual(runner.run({}), new Date().getDay(), "current weekday"); +}); +QUnit.test("Sum two float numbers as string", function(assert) { + let runner = new ExpressionRunner("{a} + {b}"); + assert.equal(runner.run({ a: "1.1", b: "2.2" }), 3.3, "#1"); + assert.equal(runner.run({ a: "0.1", b: "0.2" }), 0.3, "#2"); }); \ No newline at end of file diff --git a/tests/helperstests.ts b/tests/helperstests.ts index 21a0d80399..7e2449fec1 100644 --- a/tests/helperstests.ts +++ b/tests/helperstests.ts @@ -311,6 +311,8 @@ QUnit.test("Helpers.isNumber", function(assert) { assert.equal(Helpers.isNumber("0xabcd"), true, "0xabcd is a number"); assert.equal(Helpers.isNumber("23.3"), true, "23.3 is a number"); assert.equal(Helpers.isNumber("abcd"), false, "abcd is not a number"); + assert.equal(Helpers.isNumber("0.1"), true, "0.1 is number"); + assert.equal(Helpers.isNumber("0.2"), true, "0.2 is number"); assert.equal( Helpers.isNumber("0xbe0eb53f46cd790cd13851d5eff43d12404d33e8"), false, @@ -493,6 +495,7 @@ QUnit.test("sumAnyValues", function(assert) { assert.equal(Helpers.sumAnyValues([1, 2, 3], 4), 10, "[1, 2, 3] + 10"); assert.equal(Helpers.sumAnyValues(["a", "b", "c"], " "), "a, b, c ", "['a', 'b', 'c'] + ' '"); assert.equal(Helpers.sumAnyValues(["a", "b", "c"], ""), "a, b, c", "['a', 'b', 'c'] + ''"); + assert.equal(Helpers.sumAnyValues("0.1", "0.2"), "0.10.2", "'0.1' + '0.2'"); }); QUnit.test("isValueObject", function(assert) { assert.equal(Helpers.isValueObject("abc"), false, "abc");