How to Convert a String to Integer in Power Automate

Do you need to convert a string to an integer number in your flow?

Converting a string to an integer is a common task that is often necessary when working with data from various sources.

What looks like a number might actually come into Power Auatome as a string. This might cause errors in your flow in later steps if you are trying to manipulate them as numbers.

You will need to convert these text strings to numbers before you can perform any calculations with them.

This post will show you how to change a text value to a number in Power Automate.

Convert String to Integer

The Microsoft Forms connector is one that commonly causes issues with mixing text and numbers.

In Microsoft Forms it is possible to restrict answers to a number value.

But when retrieving this answer in Power Automate with the Get response details action, it will be a text value.

When you try and use this value in any operation that requires a number, the flow will end in error.

You will first need to convert this value to a number before you can use it as a number.

Int(outputs('Compose'))

This is quite an easy fix! You can use the Int() function to convert a string to an integer value.

The above formula will convert the Number dynamic content in the Compose action, which is from the Get response details action, to an integer.

You will then be able to use the results of this formula as a number.

You can also convert a text to a decimal number using the Float() function.

Conclusions

Values that are strings when you expect them to be a number are a common problem in Power Automate, especially when using the Forms connector.

Once you identify the issue, it’s an easy fix to first convert the text value to an integer with the Int function.

Have you come across this data type issue before? Let me know in the comments below!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

2 Comments

  1. James

    Hi! This was helpful to me but I have a question I’m hoping you can help with. I have failed repeatedly at using Int() and float() to convert string numbers to integers. I have an array that includes numbers in string format. I need to convert them into integers but I am getting the error “The template language function ‘int’ was invoked with a parameter that is not valid. The value cannot be converted to the target type” every time. Same with Float(). My data includes negative numbers but no decimals. I need the fields Points_Total and Points_Effort to be integers so I can use them in later functions.
    e.g.
    “Project Manager”: null,
    “Points_Total”: “250”,
    “Points_Effort”: “-30”,
    “Priority”: “Not Critical”,
    Thank you for any advice you can provide.
    James

    • John MacDougall

      Are you trying to use something like int(array)? I don’t think you can pass an array, only a scalar value.

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!