cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jonathan_rou
Frequent Visitor

Type Conversion Errors (decimal to int)

Good afternoon,

 

I've run into some issues with the function int() while trying to convert a decimal number to an int.

 

Here's my example: 

I have an entity on CDS that has a field called "price" that is stored as a decimal number. 

However, simply calling int() on that field throws an error, specifically "Unable to process template language expressions in action 'Compose_2' inputs at line '1' and column '2595': 'The template language function 'int' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'."

 

I've tried to make the decimal a string and then convert, but that fails with a similar message. 

 

An example price would be 2819.23. I believe the issue is contained within the int() function but would love to hear any suggestions. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Brad_Groux
Community Champion
Community Champion

If you review the Wokflow Definition Language documentation for Integer, please notice that int() requires a string:

int
Return the integer version for a string.
int('<value>')

So, your option is only really to "float" the decimal places via a variable or action. If the float value is in a variable:

substring(string(variables('VARIABLE_NAME')),0,add(indexof(string(variables('VARIABLE_NAME')),'.'),3))

If the float value is in an action:

substring(actionOutputs('ACTION_NAME'),0,add(indexof(actionOutputs('ACTION_NAME'),'.'),3))

Please see this previous post by @gamoraes  that explains the process in further detail. There is also a Currency and decimal format in Microsoft Flows idea currently "Under Review" that you may vote or comment on. 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

4 REPLIES 4
Brad_Groux
Community Champion
Community Champion

If you review the Wokflow Definition Language documentation for Integer, please notice that int() requires a string:

int
Return the integer version for a string.
int('<value>')

So, your option is only really to "float" the decimal places via a variable or action. If the float value is in a variable:

substring(string(variables('VARIABLE_NAME')),0,add(indexof(string(variables('VARIABLE_NAME')),'.'),3))

If the float value is in an action:

substring(actionOutputs('ACTION_NAME'),0,add(indexof(actionOutputs('ACTION_NAME'),'.'),3))

Please see this previous post by @gamoraes  that explains the process in further detail. There is also a Currency and decimal format in Microsoft Flows idea currently "Under Review" that you may vote or comment on. 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

v-zhos-msft
Solution Sage
Solution Sage

Hi @jonathan_rou ,

As you said, the price is float not integer.

So please take the float() for a try.

For more 'Conversion functions', please take a reference :

https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#c...

Best Regards,

Community Support Team _ Zhongys

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This code segment: substring(string(variables('VARIABLE_NAME')),0,add(indexof(string(variables('VARIABLE_NAME')),'.'),0)) worked to remove the decimal places from the decimal number. 

 

Thank you for your help.

Anonymous
Not applicable

Using the format number action makes converting the float/decimal to string easy then you just give its output to int()

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,418)