cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Super User II
Super User II

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

4 REPLIES 4
Highlighted
Super User II
Super User II

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

Highlighted
Solution Sage
Solution Sage

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.

Highlighted
Frequent Visitor

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.

Highlighted
Advocate I
Advocate I

Re: Type Conversion Errors (decimal to int)

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

Helpful resources

Announcements
FirstImage

Microsoft Ignite 2020

Check out the announcement of Power Platform content at Microsoft Ignite!

thirdImage

Experience what's new for Power Automate

Join us for an in-depth look at the new Power Automate features and capabilities at the free Microsoft Business Applications Launch Event.

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,529)