Rounding Numbers in Power Automate

By Ryan Watkins | May 25, 2022

Rounding Numbers in Power Automate Feature Image

 

If you’ve ever tried to round numbers in Power Automate, you have probably already run into the issue there is no intuitive way to do so.

Rounding Numbers in Power Automate Cloud Flows

Recently, we had a client that needed to calculate price increases based on a Product’s current price in a flow and then round the result. If you have ever spent much time working in Excel, you know there are multiple functions provided for rounding numbers. In fact, if you search “round” in the function box, you will find a list of 15 different functions:

Rounding Numbers in Power Automate Excel Search

Unfortunately, this function is not as simple in a Power Automate cloud flow, and you won’t find any results by searching it.

The Basics of Rounding Numbers in Power Automate Cloud Flows

Thankfully, there is an expression function that lets you round numbers, you just won’t find it under the Math functions. Using the formatNumber String function, you pass in a decimal number as well as a numeric format string, and it will format it the way you specify. Using the format string of “#0”, you can have it return a string of the rounded number, using conventional rounding rules (round down below .5 and up if the number is .5 or greater).

Let’s take a closer look.

For our example, we’ve created a cloud flow triggered manually with parallel branches. In each branch, we’ve initialized a variable of type float (so that we can include decimal numbers in the example), set them to 842.6 and 842.4, and named them varRoundUp and varRoundDown. This will allow you to round both ways.

After that, we initiate another variable in each branch to enter the expression we’ll use to show the output:

  • formatNumber(variables(‘varRoundUp’),’#0′)
  • formatNumber(variables(‘varRoundDown’),’#0′)

Rounding Numbers in Power Automate Basic Cloud Flows

Once we save the flow, we can run it and expand the variables. You can see that 842.6 was rounded up to 843 and 842.4 was rounded down to 842.

Rounding Numbers in Power Automate Round Up or Down

Keep in mind that the formatNumber function is a string function. This means the value returned is a string and not a number, so if you plan to insert this into a number field or manipulate it further, you need to convert it to a number first.

When you do that, you can then easily add to your expression:

  • int(formatNumber(variables(‘varRoundUp’),’#0′))

Rounding Whole Numbers in Power Automate Cloud Flows

Now you know how to do simple rounding in a flow, but what if you need to round to the nearest multiple? In our case, the client actually needed the result to be rounded to the nearest $5 instead of the nearest dollar. This requires more work in creating the expression inflow.

Keeping in mind that flow evaluates and executes expressions from the inside to the outside, the first thing we need to do inside of our formatNumber function is divide our number by the multiplier we want, in this example case, 5:

  • formatnumber(div(variables(‘varRoundUp’),5),’#0′)

Then we need to convert it to a decimal number:

  • decimal(formatnumber(div(variables(‘varRoundUp’),5),’#0′))

Then we multiply the result again by our multiplier. Once that is done, your expression should look like this:

  • mul(decimal(formatnumber(div(variables(‘varRoundUp’),5),’#0′)),5)

If we change our variables to a type of float, replace our function from the first part of this post on each branch, and change the variable name in the expression then run the flow it should look like this:

Rounding Numbers in Power Automate Nearest Multiple

You can see that the numbers are rounded to the nearest multiple of 5:

Rounding Numbers in Power Automate Rounded to Nearest Multiple

Questions?

Stoneridge Software has a team of experts that can help you navigate this solution or any others that will benefit your business. Please reach out to us so we can help optimize your experience.

Related Posts

Recommended Reading:

Performance Turning Webservices in Dynamics 365 Business Central: Migrate Your Integrations off SOAP and Move to OData or API

Dynamics 365 Business Central users will soon be unable to use SOAP web services when making application functionality available to […]

Read the Article

Stoneridge Software Selected for 2022 Microsoft US Partner Award – Dynamics 365 Business Central

Stoneridge Software is honored to be selected as a 2022 Microsoft US (MSUS) Partner Award winner for Dynamics 365 Business […]

Read the Article
6.29.22 Dynamics CRM

Reduce Manual Data & Increase Productivity with Dynamics 365 for Sales

Dynamics 365 for Sales has a ton of great features to help automate processes for you and your team to […]

Read the Article

Dynamics 365 Business Central Boolean Field Bug Temporary Fix

If you are a Dynamics 365 Business Central cloud (SaaS) customer who is using Edge or Chrome to run the […]

Read the Article

Using Non-Sequential Numbering to Prevent Locking In Your Dynamics 365 Business Central System

Running into locks in your system? Enable non-sequential numbering on your number series to prevent number series locking issues! As […]

Read the Article
6.24.22 Dynamics GP

Uncommonly Used Features: Setting Up Account Categories in Dynamics GP

This is the final part of my current series on Uncommonly Used Features in Dynamics GP. In this post, I […]

Read the Article

Increase User Productivity in Dynamics 365 Business Central with These 10 Tips

There are constantly evolving ways for you to increase user productivity in Dynamics 365 Business Central. Here are 10 tips […]

Read the Article

Star Tribune Lists Stoneridge as a Top 200 Workplace for 2022

Stoneridge Software’s emphasis on creating a positive and flexible culture has earned recognition as a top workplace in Minnesota. The […]

Read the Article
6.14.22 Dynamics GP

Uncommonly Used Features – Reconciling Sub-ledger to GL using the Reconcile Routines in Dynamics GP

As we continue the uncommonly used features series, with this post I want to show you how to reconcile your […]

Read the Article

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X