Greater Than > < Smaller Than Does Not Work Correctly

Hello,
i give you some quick examples

store | 11,00 | hello
if | {hello} < "2,00" | echo | {hello} | <------works but shouldn´t

or you can try without variable

if | 11,00 < “2,00” |
echo | ${hello} | <----- works but shouldn´t

the problem is, do I put a 0 in front of the 2?
so

11,00 < 02,00
echo | something | <---- is not work, so this works correctly

this task works, but single-digit numbers are no longer recognised correctly.

e.g.

1,00 < 02,00

would be wrong in ui.vision

can someone give me tips or help please.
I would be very grateful

You are comparing strings, not numbers. If you want to compare numbers, convert the string to a number first with parseFloat.

Plus in your case specifically: Replace the comma with a point!

The parseFloat function will only consider the parts of the string up until in reaches a non +, -, number, exponent or decimal point. Once it sees the comma it stops looking and only considers the “11” or “02” portion.

To fix this convert the commas to decimal points.

THis works:

    {
      "Name": "compare numbers",
      "CreationDate": "2021-4-2",
      "Commands": [
        {
          "Command": "store",
          "Target": "003,14",
          "Value": "pi"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "var a = ${pi}; return a.replace(',', '.');",
          "Value": "pi"
        },
        {
          "Command": "echo",
          "Target": "comma removed: ${pi}",
          "Value": "green"
        },
        {
          "Command": "store",
          "Target": "2.712345",
          "Value": "e"
        },
        {
          "Command": "if_v2",
          "Target": "${pi} > ${e}  ",
          "Value": ""
        },
        {
          "Command": "echo",
          "Target": "this is comparing STRINGS, and \"0\" is higher in the alphabet as \"2\"",
          "Value": "blue"
        },
        {
          "Command": "end",
          "Target": "",
          "Value": ""
        },
        {
          "Command": "if_v2",
          "Target": "parseFloat (${pi}) > parseFloat (${e})  ",
          "Value": ""
        },
        {
          "Command": "echo",
          "Target": "Now we are comparing numbers!",
          "Value": "green"
        },
        {
          "Command": "end",
          "Target": "",
          "Value": ""
        }
      ]
    }
2 Likes