In Power Automate, you convert a string to a number using the int() expression (e.g., int('123') returns the integer 123) or the float() expression for decimals (e.g., float('12.5') returns 12.5). These functions work in any action that accepts dynamic content or expressions, such as the Compose action, Condition, or Apply to each.
Why You Need to Convert Strings to Numbers
Power Automate often returns numbers as text. For example, when you read a value from a SharePoint list, a Microsoft Form response, or an Excel cell, the value may arrive as a string like “42” or “3.14”. If you try to use that value in a mathematical operation (like adding two fields) or compare it numerically in a Condition, the flow will fail or behave unexpectedly. The int() and float() functions convert those text values into true numbers so you can perform arithmetic, comparisons, and aggregations correctly.
How the int() and float() Functions Work
The int() function takes a string that represents a whole number and returns an integer. The float() function handles numbers with decimal points. Both functions accept a string directly or a dynamic content reference that contains a string. Here is how you use them in an expression:
int('100')→ returns 100float('3.14')→ returns 3.14int(triggerBody()?['numberField'])→ converts the value of a form field to an integerfloat(variables('myString'))→ converts a variable containing a decimal string to a float
To use these in a flow, click inside an input field, then select the Expression tab (or the lightning bolt icon) and type the expression. You can combine them with other functions, for example add(int('10'), int('20')) returns 30.
Step-by-Step: Convert a String in a Compose Action
- In your flow, add a Compose action after the step that provides the string value.
- Click inside the Inputs field.
- Select the Expression tab (the fx icon).
- Type
int(then select the dynamic content that holds your string, then close the parenthesis. Example:int(outputs('Get_response_details')?['body/age']). - Click OK. The Compose output will now be a number.
You can then reference that output in later actions using outputs('Compose') as a number.
Common Problems and How to Fix Them
The most frequent error is “The template language function ‘int’ was invoked with a parameter that is not valid”. This happens when the string is not a valid number, for example it contains spaces, commas, or currency symbols. To fix it, clean the string first using the replace() or trim() functions. For instance, if your string is “$1,234”, you can use int(replace(replace('$1,234', '$', ''), ',', '')) to get 1234. Another common issue is using int() on a decimal string like “3.14”; use float() instead. Also, if you are converting an empty string, the function will fail; you can check for emptiness with an if() condition before converting.
Choosing Between int() and float()
Use int() when you need a whole number and the source is an integer (e.g., an ID, a count, an age). Use float() when the value can have decimals, such as prices, measurements, or percentages. If you use int() on a decimal string, it will fail. If you use float() on an integer string, it will return a number with a decimal point (e.g., 5.0), which may be fine but can cause formatting issues. For most financial calculations, float() is the safer choice because it handles both integers and decimals.
Alternatives: Using the ‘Value’ Action or Data Operations
While int() and float() are the direct methods, there are other ways to convert strings to numbers in Power Automate:
- Data Operations – Compose: You can use the Compose action with the
int()orfloat()expression as described. - Initialize Variable: Set a variable’s type to Integer or Float, then assign the string value. Power Automate will attempt to convert it automatically, but this can fail silently if the string is not clean.
- Parse JSON: If your string is part of a JSON payload, you can use the Parse JSON action with a schema that defines the field as an integer or number. This converts the value automatically when the action runs.
- Excel Online (Business) – Get a Row: When reading from Excel, you can set the column type to number in the schema, but this is not always reliable.
For simple conversions, the expression functions are the most reliable and transparent.
Cost and Performance Considerations
Converting a string to a number has no direct monetary cost; it is a standard expression function. However, every action in Power Automate consumes API calls that count toward your plan’s request limits. Using a Compose action for conversion adds one action to your flow, which counts toward your monthly action quota. To minimize actions, you can perform the conversion inline within another action’s expression (e.g., in a Condition or a Send an Email action) without needing a separate Compose step. Performance is negligible; the functions execute instantly.
Safety and Data Accuracy
When converting user input, always validate the string before conversion to avoid flow failures. Use the if() function to check if the string is numeric: if(equals(variables('str'), ''), 0, int(variables('str'))). Also be aware of locale differences: some regions use commas as decimal separators. For example, “3,14” is a valid decimal in Germany but not in the US. Use replace() to normalize the string if needed. Always test with sample data that includes edge cases like negative numbers, leading zeros, and very large numbers.
Frequently Asked Questions
Can I convert a string to a number directly in a Condition?
Yes, you can use the int() or float() expression inside a Condition’s value field. For example, in a Condition, set the left side to int(outputs('Compose')) and the right side to 100. This avoids an extra Compose action.
What if my string has leading or trailing spaces?
Use the trim() function first: int(trim(' 123 ')) returns 123. Combine it with replace() for other unwanted characters.
Why does int() fail on a decimal string?
The int() function only accepts whole numbers. For decimals, use float(). If you need to round a decimal string to an integer, use int(float('3.7')) which will return 3 (truncation).
Can I convert a string to a number in a SharePoint column update?
Yes, you can use the expression in the dynamic content of the update action. For example, set the field value to int(triggerBody()?['textField']) to store it as a number.
Is there a difference between int() and the ‘Value’ function?
There is no ‘Value’ function in Power Automate expressions. The correct functions are int() and float(). Some people confuse them with Excel’s VALUE function, but Power Automate uses different names.
What happens if the string contains non-numeric characters?
The flow will throw an error when the expression runs. To avoid this, use a filter or a conditional to check if the string matches a numeric pattern using the matches() function, or clean the string with replace() before converting.
Related
- Solar Choice Battery Calculator: How to Size a Home Battery
- Hitachi Magnetic Driver Bits: What to Know
- Google Sheets XLOOKUP: How to Use It
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Data Entry Pay: Hourly Rates & Salaries in 2024Data entry pay averages between $15 and $20 per hour for most full-time positions in the United States,…
- Open CSV in Excel Without Losing Leading ZerosTo keep leading zeros when opening a CSV in Excel, do not double-click the file. In Excel for…
- Budget Tracking Spreadsheet: Plan and Review SpendingA budget tracking spreadsheet is a workbook for comparing the money you plan to spend with what you…
- How to Insert an Excel Spreadsheet into Word DocumentsTo insert Excel content into Word, copy a cell range in Excel and paste it into Word, or…
- Win + . Shortcut: What It Does and How to Use ItThe Win + . (Windows key plus period) shortcut opens the emoji panel in Windows 10 and Windows…
- Excel Hourly Schedule Template: How to Make OneThe fastest way to get an hourly schedule in Excel is to use a built-in template: open Excel,…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.