+ Reply to Thread
Results 1 to 11 of 11

Special round of numbers

Hybrid View

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Special round of numbers

    Hello everyone
    I need to round the following numbers as illustrated:
    156.381 >> 156.38
    156.382 >> 156.38
    156.383 >> 156.38
    156.384 >> 156.38
    156.385 >> 156.38

    156.386 >> 156.39
    156.387 >> 156.39
    156.388 >> 156.39
    156.389 >> 156.39

    Hope it is clear
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Special round of numbers

    Hi,

    In a formula try:
    =ROUND(A1-0.0001,2)
    In VBA try:
    Sub SpecialRounding()
    
      Dim x As Double
      Dim y As Double
      
      For x = 156.38 To 156.42 Step 0.001
        y = Application.WorksheetFunction.Round(x - 0.0001, 2)
        Debug.Print Format(x, "0.000"), Format(y, "0.00")
        
      Next x
    
    End Sub
    Lewis
    Last edited by LJMetzger; 07-08-2015 at 07:47 PM. Reason: Corrected error per MrShorty in Post #9. Minus Sign was Plus Sign.

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Special round of numbers

    Thanks a lot for reply
    I tested both the formula and the code .. It's ok except for this value 156.385 which should be 156.38 not 156.39
    Thanks a lot for help

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Special round of numbers

    Hi,

    Thanks for the rep points. I thought I had the 156.385 correct, but obviously not. I will get back to you tomorrow, unless someone else gets there first.

    Lewis

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,393

    Re: Special round of numbers

    It looks like you are trying to implement a variation of banker's rounding. Microsoft's explanation of different rounding algorithms implemented in various products: https://support.microsoft.com/en-us/kb/196652

    Note that the VBA round function uses banker's rounding. If I have correctly interpreted your goal, the easiest approach may be a simple VBA UDF. Something like:
    function roundbank(dblnumber as double, intdigit as long) as double
    'any error checking you would like
    roundbank=round(dblnumber,intdigit)
    end function
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Special round of numbers

    Thanks MrShorty for offering help
    I really can't interpret it to UDF function
    Generally thanks for helping me

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,393

    Re: Special round of numbers

    Can you confirm that it is banker's rounding (round .5 to the nearest even digit) you are trying to implement? Even if you cannot use a UDF to accomplish the task, it will help us think through native Excel functions if we know for sure what we are trying to do.

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Special round of numbers

    In fact I illustrated the expected results in my first post ..
    There are three digits after point ..
    and as for the third digit after the point from 1 to 5 to be ignored and from 6 to 9 to round up the second digit by one
    156.381 >> 156.38
    156.382 >> 156.38
    156.383 >> 156.38
    156.384 >> 156.38
    156.385 >> 156.38

    156.386 >> 156.39
    156.387 >> 156.39
    156.388 >> 156.39
    156.389 >> 156.39

  9. #9
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,393

    Re: Special round of numbers

    So it is a "always round 0.5 down" rather than banker's rounding. (I came to the wrong conclusion because the 8 in your example is even and you did not include an odd example).

    I would probably do something similar to what LJMetzger suggested, but, instead of adding 0.0001, subtract 0.0001.

    =ROUND(number-0.0001,2)

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Special round of numbers

    Yes that's perfect
    Thanks a lot for this simple and great formulas
    Thank you very much

  11. #11
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Special round of numbers

    This also appears to work.

    Formula: copy to clipboard
    =MROUND(A1,0.01)
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 01-30-2015, 11:34 AM
  2. Replies: 7
    Last Post: 11-20-2013, 10:55 AM
  3. [SOLVED] round to one of two numbers
    By Kirk in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-22-2006, 06:00 PM
  4. Round down numbers
    By Dale in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-19-2006, 09:00 PM
  5. [SOLVED] Can you round numbers to display a specific set of numbers, for e.
    By lbfries in forum Excel General
    Replies: 3
    Last Post: 04-20-2005, 05:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1