June 24, 2025

Power Automate: Converting Strings to Integers

When working with data in Power Automate, you’ll often encounter strings that need to be converted to integers for calculations or comparisons. This is a common challenge, especially when importing data from forms, CSV files, or external systems. Today, I’ll show you several methods to convert strings to integers efficiently and provide tips to avoid common errors along the way. 

The int() Function

The simplest and most direct way to convert a string to an integer in Power Automate is to use the intfunction. Let’sexplore how it works and when to use it.

I’ll go into much more detail on how the intfunction works and recommendations and pitfalls. This is only a quick overview to get you started and on your way.

Basic Usage

The “int” function takes a single parameter – the string you want to convert – and returns its integer representation. Here’s the basic syntax:

int('<string_value>')

For example, if you want to convert the string “42” to an integer:

int('42')

This will return the number 42 as an integer data type.
Let’s see how we can use it in your Flows. I’ll add a “Compose” action to demonstrate, but you can use it in any action that accepts functions. 

When we run this Flow, we’ll get the integer value 42:

Note that this will only convert integer values, so if you have a float you need another function (see below). Also, we’re providing the value directly, but if you have it in another variable or get it from another action, it will work the same way.

Alternative Method: The float() Function

Sometimes, your string might represent a decimal number, but you need it as an integer. In such cases, you can use the “float” function:

float('42.75')

This will convert “42.75” to the float 42.75, but don’t provide this value to the “int” function to convert it to an integer. The function always expects an integer value (in a string). Otherwise, you’ll get an error like this.

Unable to process template language expressions in action 'Float_to_Int' inputs at line '0' and column '0': 'The template language function 'int' was invoked with a parameter that is not valid. The value cannot be converted to the target type.

See the “int” function reference for more details as well as the “float” function to understand what makes sense in your case.

This is a common error, but let’s look at a few more.

Handling Error Scenarios

Converting strings to integers can fail in various scenarios. Let’s explore common issues and how to handle them.

Empty or Null Values

If you try to convert an empty string or null value, you’ll encounter an error:

int('')

As you can see, you’ll get the same error as before when trying to convert an invalid value. To prevent this, use a condition to check if the value exists, like this: 

int(if(empty(trim(variables('VALUE_TO_CONVERT'))),'0',variables('VALUE_TO_CONVERT')))

For this example, we’ll use a variable to quickly change the values and test the formula. The variable is called “VALUE_TO_CONVERT”.

We’re doing a few things:

  1. We’re using the “if” function to validate.
  2. Inside, we’re using the “empty” function to check the variable.
  3. We’re using the “trim” function to remove any spaces.
  4. Then, we return zero (as a string) if the value is empty. You can add any value that makes sense in your Flow here.
  5. Otherwise, we will return the value to the variable.

Non-Numeric Strings

Another common issue occurs when trying to convert strings that contain non-numeric characters:

int('42abc')

This will result in an error because “42abc” cannot be parsed as an integer.

To handle this, you will need something that catches the error. I detail how to do that here for bigger blocks of logic, but you can use a similar approach for only one action.

Practical Example: Calculating a Total

Let’s see a practical example: converting two string values to integers and calculating their sum.

First, Initialize two variables with string values:

  1. Name: NUMBER_STRING_1, Type: String, Value: “25”
  2. Name: NUMBER_STRING_2, Type: String, Value: “17”

Then let’s add a “Compose” action to convert and calculate:

add(int(variables('NUMBER_STRING_1')), int(variables('NUMBER_STRING_2')))

When we run this Flow, we’ll get 42 as a result: 

Notice that if any of the variables don’t have an int, then you will have a problem, so this is a good place to deal with the errors and adjust along the way.

Best Practices for String to Integer Conversion

Here are some recommendations to ensure your string to integer conversions work smoothly:

  1. Validate Input Data: Always check if your input is a valid number before attempting conversion.
  2. Handle Empty Cases: Use conditions as demonstrated above to provide default values for empty inputs.
  3. Use Try/Catch Pattern: Implement a pattern similar to try/catch to handle potential conversion errors. I have a template that you can use to help make your Flow resistant to issues. You can check all the details here.
  4. Consider Using Variables: Store intermediate results in variables to make your Flow more readable and easier to debug.

Final Thoughts

Converting strings to integers is a fundamental operation in Power Automate that becomes essential when dealing with numerical data. By using the “int” function and applying the error-handling techniques we’ve covered, you can ensure your Flows process numerical information correctly and reliably.

Remember that data type conversion is just one part of data processing. To build truly robust flows, combine these techniques with proper data validation and error handling to create a complete solution.

If you have any other edge cases or recommendations, please let me know, and I’ll update the article so that we can all learn together.

You can follow me on Mastodon (new account), Twitter (I’m getting out, but there are still a few people who are worth following) or LinkedIn. Or email works fine as well 🙂

Photo by Meagan Carsience on Unsplash

 

Manuel

I have 20 years of experience in automation, project management, and development. For the past 6 years, I have been writing for this website, sharing (what I think are) valuable insights and information with readers. I strive to use my expertise to create compelling and informative content that resonates with you and, hopefuly saves you time.

View all posts by Manuel →

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon