Power Automate Flows How to Compare numbers in string and int data types

Advertisements
Advertisements

When working with Power Automate Flows it is important to understanding how the tool handles different data types and functions, particularly when it comes to comparison. In this blog post, I will talk about comparing numbers in different data types.

In some cases you may encounter a situation where you need to compare two numbers that are stored in different data types. For example, you may have a number in a string variable and another number in an int variable, and you want to check if they are equal or not.

When comparing strings in Power Automate, it’s important to understand how the tool handles different data types. For example, when comparing a string value to a number, Power Automate will treat the number as a whole number, even if it’s being compared to a text field. This can cause unexpected results, as the string value of a number is different from its integer value.

In such cases it’s recommended to use the string or int function when comparing strings to numbers. This will ensure that the comparison is done correctly and the expected results are achieved.

For example, let’s say you have a string variable called strNumber that contains the value “123”, and an int variable called intNumber that contains the value 123. You can use the following expression to compare them:

int(strNumber) is equal to intNumber

This expression will return true if the two numbers are equal, and false otherwise. In addition you can use the comparison operators (such as ==, !=, <, >, <=, >=) to compare them. For example, you can use the following expression to compare the same variables as before:

Both options will work fine for simple cases where the string variable contains a valid number. However, if the string variable contains something else, such as a letter or a symbol, then both options will fail and cause an error. To avoid this, you should always validate the string variable before converting it to an int value. You can use the isInt() function to check if the string variable contains a valid number or not. The result will be true or false. For example, you can use the following expression to validate the strNumber variable:

isInt(strNumber)

This expression will return true if the strNumber variable contains a valid number, and false otherwise. You can use this expression in a condition action to decide whether to proceed with the conversion and comparison or not.

In alternative you can also try converting both variables to string.

For example, let’s say you have a string variable called strNumber that contains the value “789”, and an int variable called intNumber that contains the value 789. You can use the following expression to compare them:

strNumber is equal to string(intNumber)

This expression will return true if the two numbers are equal, and false otherwise. But not that you can’t use comparison operators (such as ==, !=, <, >, <=, >=) to compare them.

Hope this helped ☺.

Advertisements
Advertisements
Advertisements

One response to “Power Automate Flows How to Compare numbers in string and int data types”

  1. […] data types. In some cases you may encounter a situation where you need to compare two numbers … Continue reading Power Automate Flows How to Compare numbers in string and int data types Read Complete Post and Comments SBX – Two Col […]

Leave a comment

Create a website or blog at WordPress.com