cancel
Showing results for
Did you mean:
Resolver I

## Round function in power automate?

Hi All!

I have a float that I need to round to the nearest whole number. For example: 3.480987 will be "3" while 3.7685 should be "4". I can't seem to find a round function. Is there? What are some work-arounds for this if there isn't any... thank you!

-bochie

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

I wish there were a round() expression....

Please see my example below - I don't see a way to make is less complicated but I wish I could.

Here is the expression that I used:

If you like my response, please give it a Thumbs Up.

Scott
10 REPLIES 10
Super User

I wish there were a round() expression....

Please see my example below - I don't see a way to make is less complicated but I wish I could.

Here is the expression that I used:

If you like my response, please give it a Thumbs Up.

Scott
Resolver I

Thank you so much @ScottShearer ! Enjoy the weekend 🙂

Super User

One small change - I probably should have used GreaterOrEquals() rather than greater()

If you like my response, please give it a Thumbs Up.

Scott
Resolver I

@ScottShearer , yes indeed! Thank you again!

@ScottShearer  Thank you for saving my day today!

Thank you for answering this one. I was looking for the rounding option in Power Automate Flow as well. It's still not available in Flow. I hope this is coming soon.

Untill then, great solution! I got an error that it was a string. To handle this, I put the whole calculation into a Float(). Works as a charm now 🙂

Considering that the goal is to round to the nearest integer ("whole number"), this would do the work

``@{if(greater(sub(float(myNumber), int(formatNumber(float(myNumber), 'F0'))), 0.5), add(int(formatNumber(float(myNumber), 'F0')), 1), int(formatNumber(float(myNumber), 'F0')))}``

or

``@{if(greaterOrEquals(sub(float(myNumber), int(formatNumber(float(myNumber), 'F0'))), 0.5), add(int(formatNumber(float(myNumber), 'F0')), 1), int(formatNumber(float(myNumber), 'F0')))}``

Let's see a few examples:

Example 1:

Using two actions: Compose 3 and Compose 4.

In Compose 3, one uses as input the number 3.480987.

In Compose 4, one uses as input the expression

``@{if(greater(sub(float(outputs('Compose_3')), int(formatNumber(float(outputs('Compose_3')), 'F0'))), 0.5), add(int(formatNumber(float(outputs('Compose_3')), 'F0')), 1), int(formatNumber(float(outputs('Compose_3')), 'F0')))}``

This gives the following output:

Example 2

Using two actions: Initialize variable and Compose 5.

In Initialize variable one uses a float 3.7685 with the name e myNumber.

In Compose 5, uses as input the expression

``@{if(greater(sub(float(variables('myNumber')), int(formatNumber(float(variables('myNumber')), 'F0'))), 0.5), add(int(formatNumber(float(variables('myNumber')), 'F0')), 1), int(formatNumber(float(variables('myNumber')), 'F0')))}``

This gives the following output

---

Example 3

Now let us test the second case, with greaterOrEquals.

For that, one will use two actions: Compose and Compose 2

This is the output

---

Notes:

• In Power Automate, expressions need to be enclosed within the @{} syntax when added in the "Inputs" field of actions.

• Relevant read: Use expressions in conditions to check multiple values.

• If all one wants it to round up a number, one can do the following:

``@{add(int(formatNumber(Value,'F0')),1)}``

Regular Visitor

For example, if I have a number like 7.978 or 7.890, I would like it to be rounded up to 8.0. However, if the number is 7.776 or 7.678 , I want it to be displayed as 7.7 or 7.6. How can I do this?

Frequent Visitor

Have you tried

formatNumber(decimalnumber, 'F2')

New Member

All the answers here were very useful to find the best fitting solution for me.

Let's start with my final solution and then work towards the requested solution of Bochie.

I am using the following expression to round a float as string to a decimal  with one digit behind the decimal divider:

``formatNumber(add(float(triggerOutputs()?['body/score']),0.00000000000001),'F1')``

(background is, that a SharePoint calculated column is handed over to Power Automate as a string, and even if you set it in SharePoint to have one decimal digit, it will always hand over the full float)

This formula is working fine for me, but now let me make it a bit easier for you:

First, let's assume, the variable <floatVar> is already a float, so we remove the SharePoint calculated field 'score' and replace it with a placeholder, that you will have to replace in your expression:

``formatNumber(add(<floatVar>,0.00000000000001),'F1')``

and now, let's look at the rule for rounding up or off when next digit is a 5*:

for me, the requirement was, that a number 3.25 should be rounded up to 3.3, but the default for formatNumber is, that it will round off in that case.

Therefore, I have to add the smallest possible number, so that it gets a bit more than exactly 3.25 and so it rounds up.

But if you want to use the default behaviour to have 3.2 in case of 3.25, the formula is even easier:

``formatNumber(<floatVar>),'F1')``

And now, to finally answer Bochie's question, the easy round function for float/decimal numbers to whole numbers is just to set the number of decimal digits to 0:

``formatNumber(<floatVar>),'F0')``

Little bonus:

In all cases, formatNumber will only return a string, even if it looks like a number, so if you intend to do calculations, you need to again convert the resulting string to an int or float like in the following example! 😉

``int(formatNumber(<floatVar>,'F0'))``

With all these examples and tweaks, I hope everybody is now able to find the ideal solution for your exact use case.

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

Announcements

#### Back to Basics Tuesday Tip #9: All About the Galleries

This is the ninth post in our series dedicated to helping the amazing members of our community--both new members and seasoned veterans--learn and grow in how to best engage in the community! Each Tuesday, we feature new content that will help you best understand the community--from ranking and badges to profile avatars, from Super Users to blogging in the community. Our hope is that this information will help each of our community members grow in their experience with Power Platform, with the community, and with each other!     Today's Tip: All About the Galleries Have you checked out the library of content in our galleries? Whether you're looking for the latest info on an upcoming event, a helpful webinar, or tips and tricks from some of our most experienced community members, our galleries are full of the latest and greatest video content for the Power Platform communities.   There are several different galleries in each community, but we recommend checking these out first:   Community Connections & How-To Videos Hosted by members of the Power Platform Community Engagement  Team and featuring community members from around the world, these helpful videos are a great way to "kick the tires" of Power Platform and find out more about your fellow community members! Check them out in Power Apps, Power Automate, Power Pages, and Copilot Studio!         Webinars & Video Gallery Each community has its own unique webinars and videos highlighting some of the great work being done across the Power Platform. Watch tutorials and demos by Microsoft staff, partners, and community gurus! Check them out: Power Apps Webinars & Video Gallery Power Automate Webinars & Video Gallery Power Pages Webinars & Video Gallery Copilot Studio Webinars & Video Gallery   Events Whether it's the excitement of the Microsoft Power Platform Conference, a local event near you, or one of the many other in-person and virtual connection opportunities around the world, this is the place to find out more about all the Power Platform-centered events. Power Apps Events Power Automate Events Power Pages Events Copilot Studio Events   Unique Galleries to Each Community Because each area of Power Platform has its own unique features and benefits, there are areas of the galleries dedicated specifically to videos about that product. Whether it's Power Apps samples from the community or the Power Automate Cookbook highlighting unique flows, the Bot Sharing Gallery in Copilot Studio or Front-End Code Samples in Power Pages, there's a gallery for you!   Check out each community's gallery today! Power Apps Gallery Power Automate Gallery Power Pages Gallery Copilot Studio Gallery