You are comparing strings, that is why 78000 “wins” against 104000
=> The solution is to use “ParseInt” before comparing the values.
In the screenshot, note that variables that have a string as content have the ""
quotation marks (here: variables A and B) and variables with numbers do not have ""
(here: C_is_number).
{
"Name": "compare_numbers",
"CreationDate": "2024-7-31",
"Commands": [
{
"Command": "label",
"Target": "Start",
"Value": "",
"Description": ""
},
{
"Command": "store",
"Target": "104000",
"Value": "A",
"Description": ""
},
{
"Command": "store",
"Target": "80000",
"Value": "B",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "return Number (Number (${A})*0.75) .toFixed(2)",
"Value": "B",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "return parseInt((Number (${A})*0.75) .toFixed(2))",
"Value": "C_is_Number",
"Description": ""
},
{
"Command": "if",
"Target": "parseInt(${A}) > parseInt(${B})",
"Value": "",
"Description": ""
},
{
"Command": "echo",
"Target": "A is larger than B!",
"Value": "green",
"Description": ""
},
{
"Command": "else",
"Target": "",
"Value": "",
"Description": ""
},
{
"Command": "echo",
"Target": "B wins",
"Value": "blue",
"Description": ""
},
{
"Command": "end",
"Target": "",
"Value": "",
"Description": ""
}
]
}
Similar String to Integer conversion posts:
- Greater Than Less Than BUG Only On Single Digit Numbers - #2 by ulrich
- Comparing variables - #2 by ulrich
- Given my result from an OCR is 123+123 how do I get it to automatically calculate it for me and type 246 - #2 by ulrich
- Comparing 2 columns and see which one is greater in an if statement - #2 by TechSupport
- If condition not working within while - #2 by ali_raza