Round to Even (aka Banker''s Rounding) - The final function

  • You passed what?

    @Pass1?

    Right.

    What is the value @Pass1 at the moment you passed it to ROUND?

    2.2650000000000001

    That's the fact.

    You just failed to assign desired value to the variable.

    It has nothing to do with ROUND.

    Man, you're starting humiliating yourself.

    It's really essential thing.

    Please don't try to convince everybody you're that stupid.

    _____________
    Code for TallyGenerator

  • "You passed what?

    @Pass1?

    Right.

    What is the value @Pass1 at the moment you passed it to ROUND?

    2.2650000000000001

    That's the fact."

    Thank you, thank you, thank you. You just proved that the FN_BRound function performs its job admirably. Your earlier "modification" to the test I wrote stated...

    ,@pass6 = 612.945 -- should return 612.94

    ,@pass7 = 5.025000000000 -- should return 5.02

    ...which is incorrect. 612.945 is actually 612.94500000000005 long before the function ever sees it, so it should round to 612.95, which it does. 5.025000000000 is actually 5.0250000000000004 long before the function ever sees it, so that is also what is passed to the function. In this case, the function is also correct in that it returns 5.03.

    David Jackson, you need to thank Sergiy, as he just proved that your function works perfectly to his expectations.

    "You just failed to assign desired value to the variable.

    It has nothing to do with ROUND."

    You just failed to assign desired value to the variable. It has nothing to do with Banker's Rounding. Man this is fun.

    "Man, you're starting humiliating yourself.

    It's really essential thing.

    Please don't try to convince everybody you're that stupid."

    For 'tis the sport to have the enginer

    Hoist with his own petar; and 't shall go hard

    I think our work is done here.

  • David Jackson, you need to thank Sergiy, as he just proved that your function works perfectly to his expectations.

    Thanks Sergiy

    Dave J

     


    http://glossopian.co.uk/
    "I don't know what I don't know."

  • Heh heh lovely job lads!

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Really?

    Now please give me result of BR for your beloved PRECISE value 2.265

    Or 612.945

    Please prove that your function works as expected for these values.

    Can you do it?

    Is this function to be considered working if you cannot supply any desired value to it?

    Especially those which are crucial for BR functionality?

    Guys, are you really programmers?

    _____________
    Code for TallyGenerator

  • Ermm...

    select dbo.fn_Bround(2.265,100) union

    select dbo.fn_Bround(612.945,100)

                         

    ---------------------

    2.2600

    612.9500

    (2 row(s) affected)

    Yes?

    Guys, are you really programmers?

    Personally, no.  I'm a DBA Manager.

    Now off to the other thread to reply to yet more drivel.

    Dave J

     


    http://glossopian.co.uk/
    "I don't know what I don't know."

  • Which function did you use?

    With decimals of with floats?

    Last time you were talking about FLOATs.

    Changing rules again?

    Can you finally decide which version of the function to use to receive consistantly right results?

    _____________
    Code for TallyGenerator

  • Isn't 612.945 supposed to result in 612.94

    Far away is close at hand in the images of elsewhere.
    Anon.

  • No, because as Sergiy told us that number isn't what actually gets passed to the function, and as he also told us, that's not a problem with the function, but with SQL Server (actually, we all knew this a long time ago, and brought it up repeatedly, but he kept ignoring it when we brought it up until I played him like a fiddle).

    When you set a DOUBLE PRECISION variable to 612.945, behind the scenes it becomes 612.94500000000005, so that is what the Banker's Rounding function gets. It then, quite properly, rounds it to 612.95.

    Note: while it is likely that you already know the above from reading the thread, and are just making fun of Sergiy (which your smiley led me to believe might be the case), on the off chance that you're not, I wanted to explain.

  • So, you just cannot get your Bakers Rounding work correctly for 612.945.

    That's truly fun!

    As David Jackson said here:

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=370393&p=1

    SELECT dbo.fn_BRound(654.945,100) -- Wrong - 654.95

    So, you're wrong.

    It his words, not mine!

    _____________
    Code for TallyGenerator

  • SELECT dbo.fn_BRound(654.945,100) -- Wrong - 654.95

    Which is why we are here in thre first place.

    Dave J

     


    http://glossopian.co.uk/
    "I don't know what I don't know."

  • "So, you're wrong.

    It his words, not mine!"

    And I quote you again....

    ,@pass6 = 612.945 -- should return 612.94

    ,@pass7 = 5.025000000000 -- should return 5.02

    ...which is incorrect, since the function doesn't actually receive 612.945 as a parameter, nor does it receive 5.025000000000 as a parameter. So yes, those are your words.

  • Two Davids, can you agree between you two:

    what is right and what is wrong?

    It's not me arguing anymore.

    It's you 2 fighting each other.

    _____________
    Code for TallyGenerator

  • It really is quite simple.  We want a function that matches the following rules:

    * Decide which is the last digit to keep.

    * Increase it by 1 if the next digit is 6 or more, or a 5 followed by one or more non-zero digits.

    * Leave it the same if the next digit is 4 or less

    * Otherwise, all that follows the last digit is a 5 and possibly trailing zeroes; then change the last digit to the nearest even digit. That is, increase the rounded digit if it is currently odd; leave it if it is already even.

    How hard is that to follow?

    Dave J


    http://glossopian.co.uk/
    "I don't know what I don't know."

  • Another David,

    How hard is that to follow?

    _____________
    Code for TallyGenerator

Viewing 15 posts - 31 through 45 (of 378 total)

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