Strings are equal, but different? Weird string-to-string comparison behaviour

Hi. It looks like you want to compare numbers, not text strings. => You need to convert the string to a number. For this Javascript has parseFloat. But first you need to clean up your strings and remove (trim) the " " (space) and replace the comma “,” with a decimal point “.”.

{
  "Name": "number compare",
  "CreationDate": "2021-3-2",
  "Commands": [
    {
      "Command": "comment",
      "Target": "open // https://ftygu.free.beeceptor.com",
      "Value": "priceRaw"
    },
    {
      "Command": "store",
      "Target": "1399,90 €",
      "Value": "priceRaw"
    },
    {
      "Command": "store",
      "Target": "1 399,90 €",
      "Value": "priceRaw2"
    },
    {
      "Command": "comment",
      "Target": "storeText // xpath=/html/body/span",
      "Value": "priceRaw2"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var p = ${priceRaw}; p2= p.replace(\",\",\".\"); return p2;",
      "Value": "N_priceRaw"
    },
    {
      "Command": "echo",
      "Target": "Comma replaced: ${N_priceRaw}",
      "Value": "pink"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return parseFloat (${N_priceRaw})",
      "Value": "N_priceRaw"
    },
    {
      "Command": "comment",
      "Target": "Now clean up price2 => Remove . AND \" \"",
      "Value": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var p = ${priceRaw2}; p2= p.replace(\",\",\".\"); return p2;",
      "Value": "N_priceRaw2"
    },
    {
      "Command": "echo",
      "Target": "Comma replaced:  ${N_priceRaw2}",
      "Value": "orange"
    },
    {
      "Command": "comment",
      "Target": "Remove ALL spaces",
      "Value": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var p = ${N_priceRaw2}; p2= p.replace(/\\s/g, ''); return p2;",
      "Value": "N_priceRaw2"
    },
    {
      "Command": "echo",
      "Target": "Space removed: ${N_priceRaw2}",
      "Value": "orange"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return parseFloat (${N_priceRaw2})",
      "Value": "N_priceRaw2"
    },
    {
      "Command": "echo",
      "Target": "Now we have numbers: ${N_priceRaw} vs ${N_priceRaw2}",
      "Value": "blue"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return ${N_priceRaw} === ${N_priceRaw2}",
      "Value": "isEqual"
    },
    {
      "Command": "echo",
      "Target": "${isEqual}",
      "Value": "green"
    }
  ]
}

See also:

1 Like