How to Convert a String to a Decimal Number in Power Automate?

Are you trying to convert a string value to a Decimal Number value in Power Automate? This Power Automate tutorial will help to convert a string to a Decimal Number in Power Automate.

Scenario:

Whenever a user enters a decimal number value in a string data type, the Power Automate flow is considered as a text value. It will not be taken as a decimal number value.

For example:

To Perform an addition with two decimal values, we require two input values with the number data type.

So the user enters the first input value is 1.2345 with the text data type, and the second input value is 3.2345 with the number data type. While performing the addition, the flow fails.

To overcome this, we have to convert the first input String value from the text data type to a Decimal Number value of the Number data type.

Then, it performs the addition operation with the two decimal input values. So, the flow will run without any errors and display the output value of the two decimal values as expected.

Decimal function in Power Automate

  • The Decimal function returns a string containing a decimal number as a decimal number. We can use the decimal function to perform math functions.
  • This decimal function is used to wrap any decimal output with the string values.

Below is the syntax of the decimal function:

decimal('<value>')

Now we will create a flow to convert String to a Decimal Number using Power Automate Flow,

See also  Create PDF from Microsoft Forms via Power Automate

How to Convert a String to a Decimal Number in Power Automate

Let us see how to convert a String to a Decimal Number in Power Automate Flow,

1. Create an instant cloud flow, Expand the manual trigger action, and add two input values. The first input value is the text data type, and the second input value with the number data type.

power automate convert string to decimal number

2. To convert the first decimal input value from the text data type to a number data type decimal value, we will use the decimal() function.

Add a compose data operation from the action triggers and pass the below expression.

decimal(triggerBody()['text'])

Where,

  • decimal – function name
  • triggerBody()[‘text’] – first input value
convert string to decimal number using power automate flow

3. We will perform an addition with the two decimal values. (Converted text to number value with the directly passed number value).

For that, select the compose data operation and pass the below expression, which performs the addition of two decimal values with an integer data type.

add(outputs('Compose'),triggerBody()['number'])

Where,

  • add – function name
  • outputs(‘Compose’) – first input value (converted from text data type to number data type)
  • triggerBody()[‘number’] – second input value
power automate convert string to decimal

4. Save and Run the flow; enter the two input values and click on the Run flow option.

How to convert string to decimal number using flow

Once the flow runs successfully, we can see the flow performs an addition and displays the output value as expected.

convert string to decimal number in power automate flow

This is how to convert a string to a decimal number using the decimal() function in Power Automate.

Conclusion

So, I hope now you understand why we need to convert a string value to a decimal number in Power Automate flow.

See also  Power bi treemap - How to use

Using a decimal() function in Power Automate, we can easily convert the string values to a decimal number value, and this supports all the values that are text data types when you expect them to be a number data type in Power Automate.

You may also like:

>