cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jonathan_rou
Level: Powered On

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
Highlighted
Super User
Super User

Re: Type Conversion Errors (decimal to int)

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

3 REPLIES 3
Highlighted
Super User
Super User

Re: Type Conversion Errors (decimal to int)

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
Level 10

Re: Type Conversion Errors (decimal to int)

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.

jonathan_rou
Level: Powered On

Re: Type Conversion Errors (decimal to int)

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.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 152 members 5,229 guests
Please welcome our newest community members: