Bankers Rounding

  • I would name a "midnight event" "midnight". Seems like a surplus of words to do otherwise. As for what happens at 00:00, since I work in the IT world, it means a new day has started. Of course, if I worked in the legal profession, "midnight" would mean something else entirely. I take that into consideration when signing legal documents, but when programming, I switch gears. In other words, I pick whichever method of determing midnight is a best fit for the situation. Much like picking rounding methods. On that note, if you find someone in this thread who claims that this rounding method is the only one you should ever use, for all situations, feel free to point them out, and I'll gladly slap them roundly with a rancid trout.

    I realize that it comes as a shock to you, but many people survive this switching of gears on a daily basis. Those people who are unable to context switch in such a manner are the same people who missed an awesome party on Jan 1st, 2000, and instead sat around with their three pedantic friends a year later.

  • Actually, we didn't calculate taxes on a line item basis, but at the order level.  round(sum(LineItemAmt) * TaxRate, 2) = round(sum(LineItemAmt * TaxRate), 2).  The issue was distributing the taxes collected to the approriate authorities.  If you rounded the individual amounts for each authority to 2 decimal positions, the sum of each tax rate could exceed the total amount that was collected.  That was the situation, and if you disagree with the solution, that's too bad.

     

  • David, you did not answer the question:

    When the even suppise to happen to be named by you "midnight event"?

    Exectly at midnight?

    Not 1s later?

    Not 1 ms later?

    Not 1 mcs later?

    What if you've got only 2 hands clock available? How do you record all events happening between 0:00:00 including and 0:01:00 excluding?

    _____________
    Code for TallyGenerator

  • I know you asked this of David, however, I wouldn't care what time the order came in on, only what day.  If I have to choose based on a time, at exactly 12:00 AM (00:00) the orders are on the next day, unless there is a business rule that says other wise, such as all orders received on or after 6:00 PM (18:00) are treated as being received the next business day.

    This has nothing to do with rounding.

  • David F.

    If you still have the code you ised to test the Bankers Round function, it would be interesting to see it compared to the standard round function.  Willing to try?

    Lynn

  • I did answer the questions you posed, which is something you seem to avoid in return. I'll happily answer your new question, even though I'm only guessing at what you're asking. For instance, I have no clue what you mean when you say that I named something a "midnight event", when that is a term I never used in my life until responding to your use of it.

    Your questions in order:

    First, when dealing with IT specifics, then outside of the IT world, with friends, etc.

    IT specific:

    Exactly at midnight: A new day starts. Yes, even before the first picosecond has elapsed, to put an end to this thus far silly diversion of your's.

    2 hands available: Not applicable in the IT world.

    Outside of IT (for instance my friends saying meet me at midnight on Friday at Club XYZ):

    Exactly at midnight: The same day, 1 minute after 11:59 PM. As I noted earlier, while not technically correct, I'm not such a pedant that I'm going to miss out on the party because I was too stubborn to recognize that they aren't technically correct. Also at this time on the same day, a certain girl found herself without dress (not necessarily a bad thing at midnight), and with a pumpkin for transportation (she's without dress, but now she's all sticky, good thing I like pumpkin).

    2 hands available: I don't actually record events that occur between midnight and 1 minute after minute outside of IT, but if I did for some silly reason, I'd probably say "Being the OCD person that I obviously must be, since I'm recording crap that happens during a very specific minute, the following events occurred within the first minute after midnight, at least according to my watch, which because I'm OCD, I recalibrate with the Atomic clock hourly, adjusting for internet latency".

    Now, it's your turn (okay, actually it's been your turn to back up your assertions for a while now, but maybe you were too busy coming up with bizarre tangents to actually do so). First, how about actually responding to the fact that I not only performed the test that you asked, but that it showed how well banker's rounding performs?

    Secondly, a more realistic test, since your numbers were all sequential. Feel free to run this as often as you'd like, as it only takes a few minutes to run. Then, let me know how poorly the rounding method under discussion performed. Hell, if the 5 people (probably an overestimate) who are still reading this thread want to run it and post their results, that's great as well.

    Here are my results from three initial passes

    Initial ValuesConvergent RoundingTraditional Rounding
    499953.984499954.660500454.760
    500524.051500525.320501026.590
    499940.689499937.260500435.900

    Here is the code:

    DECLARE @intCounter int

    SET @intCounter = 1

    DECLARE @TestTable TABLE

     (

     InitialValue  decimal(15,4)

     ,ConvergentRound decimal(15,4)

     ,TraditionalRound decimal(14,4)

      )

    WHILE @intCounter <= 1000000

    BEGIN

     INSERT INTO @TestTable

      (

      InitialValue

       )

     VALUES

      (

      -- Feel free to increase this to more digits if you'd like, but increase the sample size counter

      -- above to match, so change to 4 digits, make it 10 million passes instead of 1. 5 digits, 100

      -- million passes. Otherwise, the sample set is way too small to get repeatable results. It's

      -- your CPU time, so make it a billion rows with 6 digits if you really want. See you next week.

      Round(Rand(),3)

       )

     SET @intCounter = @intCounter + 1

    END

    UPDATE

     @TestTable

    SET

     ConvergentRound = dbo.fn_BRound(InitialValue,100)

     ,TraditionalRound = Round(InitialValue,2)

    SELECT

     InitialTotal = Sum(InitialValue)

     ,ConvergentTotal = Sum(ConvergentRound)

     ,TraditionalTotal = Sum(TraditionalRound)

    FROM

     @TestTable

    If you have a problem with the test, say so. Hell, devise your own test (I realize you did this once before, but this time make sure it doesn't make you look bad), and as long as it isn't intentionally skewed, and has a large enough, randomly distributed sample size, I'll happily run it for you.

     

     

  • Page 6 of this thread. It's not my test, but Sergiy's (He formulated it, I coded it). He has just distanced himself from it since then, since it demonstrated how well this rounding function performs.

  • David,

    1st, there is only one world.

    IT is a technology which suppose to reflect information about this world we have collected.

    > Exactly at midnight: A new day starts. Yes, even before the first picosecond has elapsed

    OK.

    Then,

    1) event which happened on 0.5 picosecond after midnight - is it "midnight event"?

    2) how do you record in database an event happened 10 picoseconds after midnight? Can you distinguish 2 events: 0.5ps and 10ps after midnight?

    If not how you gonna record 10ps event?

    P.S. Cut the crap.

    _____________
    Code for TallyGenerator

  • Then did you enjoy the big (okay, not so big) party on 12/31/2000 with the other people who believe that IT reflects their world? Sorry, but I was partying like it's 1999 in 1999, when everyone else was, even though the new millenium wasn't "technically" due to start for over a year. I find life much more fun if I can switch context as needed. For that reason, if my friends ask me to meet them for drinks on Friday at a quarter after midnight, I'll happily show up early Saturday morning at 00:15:00 and hang out with them, without so much as mentioning that it's technically Saturday that we were meeting. Quite frankly, both they and I would find that conversation rather boring about 3 picoseconds into it.

    My answers (still waiting on your's):

    1) It is if my system doesn't handle fractional picoseconds. If my system does handle them, then it's the ".5 picoseconds after midnight event".

    2. You don't unless you are on esoteric system that can record time in intervals so small that light only travels a couple of millimeters between time changes. I don't work on such a system, so I don't worry about it. If my needs required recording a 10ps event, then I'd have to use a system capable of differentiating between times that small. Those aren't my needs, so I don't do so.

    Crap? A bazillion pages of you dancing around the fact that you were wrong, still are wrong, and from what I can tell, will still be wrong tomorrow, even after midnight, and I'm the one dishing out crap?

    How about an actual response to the questions posed to you?

  • Sergiy,

    This is getting really rediculous.  What in the world is a 'midnight event' and if it is something that occurs at 'midnight' then it occurs at 'midnight', not 10 picoseconds after midnight or 10 pico seconds before midnight.  I am also waiting for you to explain what the heck this has to do with rounding, in any sense of the word.

    You have taking this topic so far off course nobody knows where it may go next.  You've gone from rounding, to midnight, to the Spanish Inquesition?  Where next, that the Apollo landings on the moon were faked by Hollywood?

  • So, your answer depends on precision you can measure time intervals.

    If the smallest interval you can measure is 1ps then "midnight event" is an event happened between 0:00:00.000.000.000.000 and 0:00:00.000.000.000.001(excl)

    If the smallest interval you can measure is 3ms (in case of MS SQL Server) every event happened between start of the day and 0:00:00.003(excl.) will be recorded as 0:00:00.000 (because it happened before the system clock ticked) and would be interpreted by anyone reading the data as "midnight event"

    Is it right?

    _____________
    Code for TallyGenerator

  • Mean while, the price of tea in China just went up!

  • Sergiy,

    Honestly, I'd take you more seriously if you'd take the time to answer ALL the questions that have been put to you that you have chosen to ignore.

  • Lynn, as you could notice I'm not talking to you.

    You refused to continue with this discussion at least twice.

    It's not a style of discussion I could accept.

    So, shut up, please.

    _____________
    Code for TallyGenerator

  • Getting nasty isn't going to get rid of me.  It is, in fact, a sign of desperation on your part.  Just answer the questions that have been posed to you.  This is a professional community web site, how about starting to show some professionalism.

    I'm sure you have heard the saying you catch more flies with honey than vinegar, well, if you'd treat people with more respect, you'd get that same respect back.

Viewing 15 posts - 106 through 120 (of 373 total)

You must be logged in to reply to this topic. Login to reply