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

Round a Float

I need to round the value of a number that the flow will get from a file property.

What I want is to get this float x.yz and tranform it into x.00 (or an integer).

 

I have tried to use Int() but it seems it doesn't work.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
yashag2255
Dual Super User II
Dual Super User II

Hi @MLM 

 

Please see the screenshot below:

int.PNG

Expression:

int(first(split(string(variables('ee')),'.')))

This converts the float to string and extracts the part before the decimal and then converts that to int. 

 

Hope this Helps!

 

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

13 REPLIES 13
yashag2255
Dual Super User II
Dual Super User II

Hi @MLM 

 

Please see the screenshot below:

int.PNG

Expression:

int(first(split(string(variables('ee')),'.')))

This converts the float to string and extracts the part before the decimal and then converts that to int. 

 

Hope this Helps!

 

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

MLM
Frequent Visitor

This works.

Great Thank you!


@yashag2255 wrote:

Hi @MLM 

 

Please see the screenshot below:

int.PNG

Expression:

int(first(split(string(variables('ee')),'.')))

This converts the float to string and extracts the part before the decimal and then converts that to int. 

 

Hope this Helps!

 

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!


 

This is a ridiculous workaround. Why doesn't MS Flow just have Round functions built-in? I have to instantiate TWO variables and have a five nested function calls? Absolutely absurd.

absolutely agree with this.. i'm dealing with excel datetime columns which already provides an excellent amount of confusion with their serialized time. Seems like the only way to convert it to an understandable datetime for flow, I have to do something similar to this..
having to convert a floating point to a string and then back to int and float is mindbogglingly absurd.

 

The way datatypes are being dealt with is causing so much annoyance and frustrations 😕 

 

/rant 

yashag2255
Dual Super User II
Dual Super User II

Hi @hjaf , And folks visiting this thread now, 

 

A new action named Format Number has been introduced in Power Automate that can be directly used now to format a number (decimals/ currency/ commas etc). You might want to check that out as well. 

 

Hope this Helps!

 

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!

mizsei
Advocate I
Advocate I

This not a solution! This only can be good, if you want a trunc function. I don't know how to deal with this.

irondinges
Advocate II
Advocate II

I worked around this ridiculous issue by doing a manual round up by addition.

1. Divide your number

2. Add 0.5 (if you want to round to nearest) or 0.9999 (if you want to round up, as I did in my case. Will have to configure based on your data/accuracy desired)

3. Convert to int, which will chop off everything beyond the decimal.

 

My use case for this was to calculate how many SMS's a message will split into (as there is a limitation of 153 characters), and it was important for me to have 154 characters become 2 SMS's (round up).

@irondinges  your workaround is a perfect solution. Thank you!

Billy_C
Helper V
Helper V

Hi,

 

It seems that rounding functions are still not included in Power Automate nor Powerapps.
I do not understand why this is not yet implemented, even excel has more functions then powerapps can provide.
This cannot be right, a product as powerapps has so much potential with all these complexities built-in, but most common used and simplest of things are not implemented and rather thrown away.
I understand what the goal is for powerapps but I feel like the most important basic parts are being forgotten.
If I create an app in Powerapps It would takes 10x maybe even more time longer then it is to make the same app in excel. Ofcourse powerapps has the possibility to have many more connections and it is a good thing but instead it would be better to focus to increase its flexibility, use of formulas and its speed cause sometimes powerapps and flows can be really really slow (and no its not due to my internet connection i have an excellent connection so).

Still I don't think that powerapps is bad or anything like that, but I would rather say that its still in beta mode and is still far from being a finished product. Which is also why I wouldn't recommend using it just yet, but I might if enough improvements have been made.

 

Can't wait to see how Powerapps will evolve in the future!

 

Thanks in advance,

 

Billy Cottrell

hjaf
Advocate V
Advocate V

I wrote a long response, only to lose everything when clicking reply.. 😒

 

TL;DR (as in too long didn't rewrite):

Still not in expressions:
https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#m...

 

Both powerapps and power automate desktop has functionality:
Power Automate Desktop: 
https://docs.microsoft.com/en-us/power-automate/desktop-flows/actions-reference/variables#truncatenu...

Power Apps:
https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-round

Billy_C
Helper V
Helper V

Hi @hjaf,

 

Yeah I also get these kind of issues myself, normally it saves every so often so you should be able to load in a draft of it, but doesn't always work so I just try to copy it regularly to make sure I still have it.

Anyways it is true that there is a truncate method, but you can round numbers in 3 different ways that truncate method isn't able to do this. Truncate is a round up method, but what about regular rounding or rounding down, this is not available. One would need to implement these simple functionalities themselves instead of being able to focus on the more complex stuff.

Same is for powerapps you are showing canvas applications which indeed provides alot more functionalities, although that this cannot be said for model driven applications. Model driven applications have almost no formalas to be used only things like +, -, /, *, trim, multiple formulas to add or subtract days months etc but that's it. To be able to use rounding functions we literally need to add 3 fields, 1 with the base calculation of type decimal, 1 is an integer (whole number) which is set to the decimal value (so a standard rounding applies) and then the actual field that calculates which value it is supposed to be. But things like modulo, floor, ceil, etc... are just not available.

For example I have a project in my model driven app and I want that every so often a new invoice is being generated, this could be once a year or every 3 or 4 months. So if I want to create an invoice on a certain date, I would need a date field, a field that calculates the current year of the project in decimal form, then that same field in whole number form, to then actually have a different field that calculates how to round the value correctly. So now if its day 10 its year 1, if its day 364 its still year 1, day 365 its year 2 (or something like that its still 1day of but that's okay) this method is so good It's able to calculate in real time what year it is and I have a flow running every day to check which projects need a new invoice based on that field.

 

I am glad  that I was able to even do it this way, even though its not how its supposed to be. If it wasn't possible I don't think that we would be using this system still when something as easy as rounding is blocking yearly invoicing. Even if it is something that could be calculated every day with flow, because there would be too many api requests which would result in flows that no longer work since we reached the maximum amount of api requests within 24h, which I almost reached.

 

Either way I am hoping that both Powerapps and Power Automate will improve these formulas so the most basic of things can be done without running against any limits (which there are too many of).

 

Can't wait to see those improvements!

 

Thanks in advance,

 

Billy Cottrell

terom
New Member

I also would like to see rounding functions in expressions (Power Automate).

 

I came up with this kind of workaround for rounding up a number after division with integers:

 

if( greater( mod( num1, num2 ), 0 ), add( div( num1, num2 ), 1), div( num1, num2 ) )

 

Basically, when dividing two integers (num1/num2), if there is a remainder greater than 0, add one to the result to round it up to the next integer.

Hello @yashag2255,

Thank you for providing this expression - it helped me at least complete a flow that I was struggling with because I was trying to run a calculation expression with numbers stored as text (from SharePoint form) in both integer and floating decimal type numbers. I figured out how to convert the text numbers to string format and used this expression on 3 fields to convert to integer and calculate a sum of those 3 fields.

The only problem is that this approach effectively rounds down to the whole number for floating decimal values which results in a very slight under-reporting in the total calculation and ideally we could convert everything to float so we could calculate a more accurate total.

 

Is there an inverse to this expression that would change integer data (i.e. 3) into a floating decimal value (i.e. 3.00) so that a more accurate total could be calculated?

If not, is there another approach that would could recommend exploring?

 

Thanks.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

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.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,627)