Converting things is essential, and Power Automate has a few functions to help us in doing that. Today we’ll focus on the float function that converts values into a floating number. Ok, it’s pretty self-explanatory, but there are some things to understand.
Let’s take a look.
How to use the float function?
It follows a simple pattern.
- Value to convert
Let’s start with a simple example. First, convert a float value from a string.
float(variables('STRING_TO_CONVERT'))
'-1'
will return
-1
The string needs to contain a valid number; otherwise, the conversion fails with the following error:
Unable to process template language expressions in action 'Convert_string' inputs at line '1' and column '4480': 'The template language function 'float' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'.
How about integers?
float(variables('INT_TO_CONVERT'))
12
will return
12
Exactly what we expect. Now let’s try with a negative value to see what happens:
float(variables('NEGATIVE_INT_TO_CONVERT'))
-12
will return
-12
So far, all of them are doing exactly what we expect them to do. First, let’s look at complex objects like arrays.
float(variables('ARRAY_TO_CONVERT'))
will return an error
It’s not possible to convert array objects into a Float. So we’ll get the following error:
Unable to process template language expressions in action 'Convert_the_array' inputs at line '1' and column '4480': 'The template language function 'float' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'.
Finally, let’s try with “null.”
float(null)
will return an error.
Here’s the error:
Unable to process template language expressions in action 'Convert_a_null_value' inputs at line '1' and column '4481': 'The template language function 'float' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'.
It behaves the same way as the “bool” function but is different from the “string” function.
Limitations
Depending on the size of your float and nested functions, your expression may return an error, even if it’s correct. Please note that the expressions have a max size of 8,192 characters. If you have an expression that is even bigger than 1000, I would strongly advise breaking it into smaller, manageable formulas.
Recommendations:
Here are some things to keep in mind.
Please don’t do it on floats.
It’s a waste to do it on float variables since they are already floating. There’s no real reason to convert a value into itself, but please let me know if you know of a good reason to do it.
Don’t nest
There’s no real reason to do it. However, if you find yourself in a situation where you have nested float functions in a formula, you should review it because it will be a mistake 99% of the time.
Sources:
Microsoft’s join Function Reference
Back to the Power Automate Function Reference.
Photo by Joe Calata on Unsplash