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!

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
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (1,385)