Skip to main content

Notifications

Community site session details

Community site session details

Session Id : /iUeNZsGtdk+fDgcbCPCym
Power Automate - Building Flows
Answered

Round function in power automate?

Like (0) ShareShare
ReportReport
Posted on 1 Oct 2021 16:46:48 by 237

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

  • aismaili Profile Picture
    7 on 10 Aug 2023 at 16:46:49
    Re: Round function in power automate?

    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.

     

    See also this site for a definition of formatNumber expression:

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

  • lewiscarr81 Profile Picture
    14 on 20 Jul 2023 at 14:56:14
    Re: Round function in power automate?

    @Bochie 

     

    Have you tried

    formatNumber(decimalnumber, 'F2')

     

    Screenshot 2023-07-20 155355.png

    Which Should return your answer to 2dp

    Screenshot 2023-07-20 155410.png

  • trixxxxxxx123 Profile Picture
    2 on 02 Jun 2023 at 04:29:22
    Re: Round function in power automate?

    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?

  • goncaloperes Profile Picture
    85 on 18 Apr 2023 at 10:55:18
    Re: Round function in power automate?

    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')))}

     

     

     

     

    goncaloperes_0-1681814187945.png

    This gives the following output:

     

    goncaloperes_1-1681814214221.png

     

    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')))}

     

     

     

    goncaloperes_2-1681815198666.png

    This gives the following output

    goncaloperes_3-1681815245821.png

    ---

    Example 3

     

    Now let us test the second case, with greaterOrEquals.

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

    goncaloperes_0-1681822739146.png

    This is the output

    goncaloperes_1-1681822813775.png

     

     

    ---

    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)}

     

     



  • timothy_bohte Profile Picture
    44 on 28 Feb 2022 at 14:50:17
    Re: Round function in power automate?

    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 🙂 

  • lras1202 Profile Picture
    52 on 22 Dec 2021 at 13:07:49
    Re: Round function in power automate?

    @ScottShearer  Thank you for saving my day today!

  • Bochie Profile Picture
    237 on 04 Oct 2021 at 23:12:13
    Re: Round function in power automate?

    @ScottShearer , yes indeed! Thank you again!

  • ScottShearer Profile Picture
    25,208 Most Valuable Professional on 01 Oct 2021 at 23:59:15
    Re: Round function in power automate?

    @Bochie 

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

  • Bochie Profile Picture
    237 on 01 Oct 2021 at 21:05:43
    Re: Round function in power automate?

    Thank you so much @ScottShearer ! Enjoy the weekend 🙂 

  • Verified answer
    ScottShearer Profile Picture
    25,208 Most Valuable Professional on 01 Oct 2021 at 19:05:39
    Re: Round function in power automate?

    @Bochie 

    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(greater(Mod(outputs('Compose'),1),0.5),add(int(first(split(string(outputs('Compose')),'.'))),1),first(split(string(outputs('Compose')),'.')))
     
    image.png
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,651 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard