Skip to main content

Notifications

Community site session details

Community site session details

Session Id : MLBsC8QYMqNjk7I2Fhu5Qd
Power Apps - Building Power Apps
Answered

How to round to the nearest even number?

Like (0) ShareShare
ReportReport
Posted on 27 Nov 2020 09:34:36 by 30

for example:

 

0.41 to 0.44, when rounded is 0.4

0.46 to 0.49 when rounded is 0.5

 

for 0.45, as it is 0.05 difference after rounded will be 0.4 as 4 is even number

0.5 is an odd number, so we cannot round to 0.5. It only can be rounded to an even number.

another example,

 

0.55 = 0.6

0.65 = 0.6

0.75 = 0.8

  • Verified answer
    v-xiaochen-msft Profile Picture
    on 01 Dec 2020 at 03:56:55
    Re: How to round to the nearest even number?

    Hi @aqidahadiqa ,

     

    Could you tell me:

    1. Whether the input number has two decimal places, the result will be kept one decimal place? (For example: 5.735.7 , 5.755.8, 5.765.8, 5.855.8)
    2. Whether the input number has three decimal places, the result will retain two decimal places? (For example: 5.735.7 , 5.755.8, 5.765.8, 5.855.8)
    3. Do you have any other needs? For example, other decimal places? How many digits should they keep?

     

    I modified the formula and the formula can satisfy the condition 1 and condition 2 mentioned above.

    In addition, when the number does not belong to Condition 1 or Condition 2, the digital output is equal to the input.

     

    You can refer to the following formula:

    1\ Set buttons onselect property to:

     

    Set(Var,***) //*** is a number

     

     

    2\ Set labels Text property to:

     

    If(
    
     Len(
    
     Mid(
    
     Text(Var),
    
     Find(
    
     ".",
    
     Text(Var)
    
     ) + 1,
    
     8
    
     )
    
     ) = 3,
    
     If(
    
     RoundDown(
    
     Mod(
    
     Var * 1000,
    
     10
    
     ),
    
     0
    
     ) = 5 && Mod(
    
     RoundDown(
    
     Var,
    
     2
    
     ) * 100,
    
     2
    
     ) = 0,
    
     RoundDown(
    
     Var,
    
     2
    
     ),
    
     RoundDown(
    
     Mod(
    
     Var * 1000,
    
     10
    
     ),
    
     0
    
     ) = 5 && Mod(
    
     RoundDown(
    
     Var,
    
     2
    
     ) * 100,
    
     2
    
     ) = 1,
    
     RoundUp(
    
     Var,
    
     2
    
     ),
    
     Round(
    
     Var,
    
     2
    
     )
    
     ),
    
     Len(
    
     Mid(
    
     Text(Var),
    
     Find(
    
     ".",
    
     Text(Var)
    
     ) + 1,
    
     8
    
     )
    
     ) = 2,
    
     If(
    
     RoundDown(
    
     Mod(
    
     Var * 100,
    
     10
    
     ),
    
     0
    
     ) = 5 && Mod(
    
     RoundDown(
    
     Var,
    
     1
    
     ) * 10,
    
     2
    
     ) = 0,
    
     RoundDown(
    
     Var,
    
     1
    
     ),
    
     RoundDown(
    
     Mod(
    
     Var * 100,
    
     10
    
     ),
    
     0
    
     ) = 5 && Mod(
    
     RoundDown(
    
     Var,
    
     1
    
     ) * 10,
    
     2
    
     ) = 1,
    
     RoundUp(
    
     Var,
    
     1
    
     ),
    
     Round(
    
     Var,
    
     1
    
     )
    
     ),
    
     Var
    
    )

     

     

    If you have more needs, please tell me and I will be happy to help you.

    Best Regards,

    Wearsky

  • aqidahadiqa Profile Picture
    30 on 30 Nov 2020 at 10:01:18
    Re: How to round to the nearest even number?

    when we rounded to nearest number for 0.45, after rounded must be even number

     

    eg:

    0.45 rounded is 0.4

    0.55 rounded is 0.6

    0.65 rounded is 0.6

  • aqidahadiqa Profile Picture
    30 on 30 Nov 2020 at 09:56:22
    Re: How to round to the nearest even number?

    Thank you @v-xiaochen-msft , 

     

    regarding to your questions, 

     

    1. nope.. some number will be 2 decimal places.  for example 0.445 will be 0.44

    2. yes

    3. the judgement took place for the last digit is 5 && follow their decimal places.. some input need  1 decimal place, some input have 2 decimal places.

    4. yes

     

  • aqidahadiqa Profile Picture
    30 on 30 Nov 2020 at 09:44:09
    Re: How to round to the nearest even number?

    I know there is the function that can be used but the think is I don't know how to do. 😅 

  • v-xiaochen-msft Profile Picture
    on 30 Nov 2020 at 07:59:38
    Re: How to round to the nearest even number?

    Hi @aqidahadiqa ,

     

    Could you tell me:

    1. Do you want to keep one decimal place?
    2. Do you want to rounddown it when the second decimal place is 1-4? (For example: 0.33 0.3)
    3. Do you want to judge the round based on the first digit after the decimal point when the second digit after the decimal point is 5?(For example: 0.35 0.4)
    4. Do you want to roundup it when the second decimal place is 6-9? (For example: 0.36 0.4)

     

    If so, the point is to judge the following three conditions:

    1. When the second digit after the decimal point is not 5, Use the round() function to round.
    2. When the second digit after the decimal point is 5, judge whether the previous digit is even. If so, use rounddown() function.
    3. When the second digit after the decimal point is 5, judge whether the previous digit is even. If not, use roundup() function.

     

    I've made a test for your reference:

     

    1\ Add a button control and set its onselect property to:

    Set(Var,5.75) // Var is a variable

     

    2\ Add a label control and set its Text property to:

    If(
    
     RoundDown(
    
     Mod( // Mod() Returns the remainder of a division.
    
     Var * 100,
    
     10
    
     ),
    
     0
    
     ) = 5 && Mod( // Judge whether the second digit after the decimal point is 5.
    
     RoundDown( 
    
     Var,
    
     1
    
     ) * 10,
    
     2
    
     ) = 0, // Judge whether the first digit after the decimal point is even.
    
     RoundDown( // execute rounddown() function
    
     Var,
    
     1
    
     ),
    
     RoundDown(
    
     Mod(
    
     Var * 100,
    
     10
    
     ),
    
     0
    
     ) = 5 && Mod( // Judge whether the second digit after the decimal point is 5.
    
     RoundDown(
    
     Var,
    
     1
    
     ) * 10,
    
     2
    
     ) = 1, // Judge whether the first digit after the decimal point is odd
    
     RoundUp( // execute roundup() function
    
     Var,
    
     1
    
     ),
    
     Round( // execute round() function
    
     Var,
    
     1
    
     )
    
    )

    3\ The result are as follow:

    v-xiaochen-msft_0-1606723092770.png

     

    v-xiaochen-msft_1-1606723092773.png

     

     

    v-xiaochen-msft_2-1606723092774.png

     

     

    Best Regards,

    Wearsky

  • 365CornerDawid Profile Picture
    377 on 27 Nov 2020 at 10:36:58
    Re: How to round to the nearest even number?

    Hey @aqidahadiqa 

    Power have the 3 functions which can help you to achive this results:
    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-round

     

    • Round rounds up if the next digit is a 5 or higher. Otherwise, this function rounds down.
    • RoundDown always rounds down to the previous lower number.
    • RoundUp always rounds up to the next higher number.

    365CornerDawid_0-1606473789303.png

    365CornerDawid_1-1606473829816.png

     

     

     

    Hope this will help you if yes please remember to mark this answer as solution to help other community members to find resolutions faster.
    Regards
    Dawid

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

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,668 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard