Convert String to Float in Power Automate
Introduction
Power Automate frequently works with data coming from multiple sources such as SharePoint, Dataverse, Excel, SQL Server, APIs, and Forms. In many cases, numeric values are received as text strings instead of numbers.
What is a Float Value?
A float represents a decimal number. Examples: 10.5, 25.75, 100.99, 0.25. Unlike integers, float values can contain decimal places.
Why Convert String to Float?
Many data sources return values as strings. For example, "125.50". Although this looks like a number, Power Automate treats it as text. To perform calculations, the value must first be converted into a float.
Solution Overview
Workflow: GetData, Receive String Value, Convert to Float, Perform Calculation, Store Result. This process ensures accurate mathematical operations.
Understanding the Float Function
Power Automate provides the float() function. Syntax: float('125.50'). Output: 125.5. The string value is converted into a decimal number.
Step 1: Create a Flow
Create an Instant Flow, Automated Flow, or Scheduled Flow. Choose the appropriate trigger based on your requirement.
Step 2: Receive String Data
Example value: "250.75". This value may come from SharePoint, Dataverse, Excel, Forms, API Response. Power Automate initially treats it as text.
Step 3: Convert String to Float
Add a Compose action. Expression: float('250.75'). Output: 250.75. The result is now a numeric value.
Using Dynamic Content
Example: float(triggerBody()?['Amount']). If Amount = "500.25", Output: 500.25. This approach is commonly used with dynamic data.
Performing Calculations
After conversion: Expression: add(float('100.50'), float('50.25')). Output: 150.75. Without conversion, Power Automate may treat the values as text.
Working with SharePoint Data
Suppose a SharePoint column stores: "1000.50". Expression: float(items('Apply_to_each')?['Amount']). Result: 1000.5. You can now perform calculations and reporting.
Working with Dataverse Data
Dataverse integrations often require numeric conversions. Example: float(outputs('Get_Row')?['body/crm_amount']). Result: Decimal value available for calculations.
Real-World Example
Invoice Processing. Requirement: Invoice Amount: "1500.75", Tax: "150.25". Convert both values. Calculate: Total = Invoice + Tax. Result: 1651.00. Power Automate handles calculations accurately after conversion.
Common Errors
Invalid Format: Example: float('ABC'). Result: Error. Because the value is not numeric. Empty Values: Example: float(''). Result: Error. Always validate values before conversion.
Safe Conversion Method
Use: if(empty(triggerBody()?['Amount']), 0, float(triggerBody()?['Amount'])). This prevents flow failures.
Best Practices
Validate Input Data: Ensure values contain valid numbers. Handle Null Values: Use conditions before conversion. Use Compose for Testing: Verify outputs before calculations. Standardize Number Formats: Ensure decimal separators are consistent. Implement Error Handling: Prevent flow failures due to invalid input.
Benefits
Accurate Calculations: Perform mathematical operations correctly. Better Data Processing: Transform incoming data efficiently. Improved Reporting: Generate reliable reports and dashboards. Reduced Errors: Avoid data type mismatches. Enhanced Automation: Support complex business processes.
Conclusion
Converting strings to float values in Power Automate is a common requirement when working with data from SharePoint, Dataverse, Excel, APIs, and other systems. Using the float() function ensures values are treated as decimal numbers and can be used in calculations, comparisons, and reporting. By implementing proper validation and error handling, organizations can build reliable and scalable Power Automate workflows that process numeric data accurately and efficiently.