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

  • "Again, prove that TR sees the precise number 0.3333 as all values between 0.3333(0) and 0.3333(9). That's all you need to do. "

    Is it your words?

    So, don't skip around.

    _____________
    Code for TallyGenerator

  • Happily, and since you're way behind in question answering, coding, proving, etc., you get to go first.

     

  • "That's all you need to do."

    Was it you or somebody else?

    You're making really funny noises, David.

    _____________
    Code for TallyGenerator

  • Actually Sergiy, 0.1250 is precisely the value you get from the ratio 1/8.  Divide it out on paper after the 0.125, all you will ever get is zeros.

  • What the hell, it's not like you're actually going to prove anything, and this stuff is way too easy, so here goes.

    1) The way TR rounds 0.1250 shows that it takes 0.1250 as > 0.1250(0);

    SELECT

    GuessWhat = CASE WHEN Round(.1250,3) > .12500 THEN 'Sergiy is Correct' ELSE 'Oops, wrong yet again' END

    2) The way TR rounds 0.1249 shows that it takes 0.1249 as < 0.1250(0) = 0.1249(9);

    This doesn't even make sense. Yes, TR sees 0.1249 as less than 0.12500 (so does BR, not that it makes any difference), but that doesn't prove that it equals .12499. In fact, let's go ahead and prove that one wrong as well. Since I proved using your logic that 0.1249 = 0.1254, it can't be equal to 0.12499. This one's not only wrong, it's silly.

    SELECT

    GuessWhat = CASE WHEN Round(0.1249,3) = Round(0.1254,3) THEN 'I proved 0.1249 and 0.1254 are the same number' ELSE 'Sergiy is right!' END

    3) There is no any customisation in TR for treating supplied values. That leads to a conclusion that 0.1250 is not only > 0.1250(0) but < 0.1250(9) as well;

    Well, I just proved your "conclusion" wrong after the first question. You really should be more careful with your use of that word.

    4) There is no any customisation in TR for treating supplied values. That's why any value #.#### will be taken as > #.####(0) and < #.####(9);

    Hmm, I'd expect to see something other than zeroes at the end here then. Guess you're wrong again.

    SELECT

    LetUsExposeMoreDigitsForSergiy = Round(.1250,3) * 1.000000

    5) Number 0.3333 fits the format specified above, so it will be treated the same way. As a value between 0.3333(0) and 0.3333(9).

    Well, since you took a wrong turn the second you left your driveway, I can't blame you for getting lost along the way.

    SELECT

    WrongAgain = Round(.3333 * 1.00000,5)

    Since we're on a roll, let's go ahead and prove your other assertion wrong. Remember that code I posted a little while back, showing that BRound does indeed return different values for .1251 when run against the original value versus the value rounded to 3 digits? The one where you say that that's an error in the function. Feel free to change that to .1249. Oops, now we have to fix the Round() function as well, as it is equally broken. Man, this is easy. Hell, I'll even save you the trouble:

    SELECT

    Sergiy

    = Round(.1249,2)

    ,IsWrong = Round(Round(.1249,3),2)

    Have a good night. I'd recommend a math book under your pillow. Since there are magic functions in your world, maybe there are magic pillows as well, and it might just work.

  • 1. You typed "Round(.1250,3)"

    But the whole thing was about rounding to 2 decimal numbers.

    That's where TR and BR return different results.

    So, keep to the topic.

    You typed there "> .12500"

    It's not .1250(0)

    You failed to prove anything.

    Sorry. You've made funny noises again.

    2. You proved that they rounded to the same number, not that they are the same.

    Yes, you've proved you've been silly.

    3. As soon as you so far produced nothing but funny noises my statements are still right.

    4. LetUsExposeMoreDigitsForSergiy cannot be more precise than any of numbers participation in the operation.

    Sorry, you did not listen to your teacher when he/she told you that.

    ROUND(..., 3) leaves not more than 3 precise digits, all others are irrelevant.

    David Burrows was struggling to prove his point about "implied zeros" fut he failed.

    Ooops, funny noise from you again.

    5. Same silly mistake. Did you actually achieve in school?

    And at the end:

    I would not recommend a math book under your pillow. I'm afraid it would not work for you. You missed too much, so you really need to read it very carefully.

    Second rounding inherits rounding inaccuracy from the first one.

    Sequential rounding is not corrects math operation and brings wrong results in some cases.

    It's expected, it's described in school books, and kids achieved in school know that.

    Sorry, the last sentence was not about you.

    _____________
    Code for TallyGenerator

  • Stephen Falken: Except, that I never could get Joshua to learn the most important lesson.

    David Lightman: What's that?

    Stephen Falken: Futility. That there's a time when you should just give up.

    Jennifer: What kind of a lesson is that?

    Stephen Falken: Did you ever play tic-tac-toe?

    Jennifer: Yeah, of course.

    Stephen Falken: But you don't anymore.

    Jennifer: No.

    Stephen Falken: Why?

    Jennifer: Because it's a boring game. It's always a tie.

    Stephen Falken: Exactly. There's no way to win. The game itself is pointless! 

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • > Because it's a boring game.

    Yeah, you're right.

    It becomes really boring.

    Guys are so low, they don't even understand the level of stupidity they expose.

    Mathematical abstraction is something beyond their imagination.

    Simple counting - that's the level of their math knowledge.

    And they clearly not interested in finding truth and learning from it.

    Unfortunately I cannot put brains in their heads, but at least I had some fun.

    And I honestly tried to help them.

    THey don't want it - sorry for them.

    _____________
    Code for TallyGenerator

  • I've been watching this thread from the start and have learned some interesting stuff about mathematics, so thank-you everyone for that. 

    However, anyone thinking of joining SSC, after reading the way in which some people address others in this thread, would probably run a mile.  Sometimes it's difficult to ask for help, especially for people with little SQL Server experience as they know their problems are likely very simple to resolve.  No-one should feel that they are going to be ridiculed for asking a question, however basic it might be, but reading this thread, that’s what they might well expect.  Deriding other people's opinions, questioning their education, doubting their intelligence and just being downright rude, are detrimental to open debate and do nothing to further anyone's thesis.  Neither do they portray SSC as the friendly and helpful community I've found it to be over the last couple of years.  Which is a shame.

  • quote David Burrows was struggling to prove his point about "implied zeros" fut (sic) he failed.

    No I did not fail

    As I already stated:-

    a)  1 - 0.33 = 0.67   (Do it on a calculator)

    b)  To achieve the result the integer 1 has to have implied fractional zeroes added to enable to subtraction to occur

    QED

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

  • Quite right, well put

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

  • You are boring, David.

    Show everyone how implied zeros can make it true:

    1/3(money + implied zeros) - 1/3(decimal(12,6) + implied zeros) = 0.00 (whatever datatype + implied zeros)

    (Do it on a calculator)

    As I said - simple counting is the limit of your math competence.

    Sorry.

    _____________
    Code for TallyGenerator

  • OK for the last time

    1 divided by 3 as (money + implied zeros) = 0.0000(0)

    1 divided by 3 as (decimal(12,6) + implied zeros) = 0.000000(0)

    0.0000(0) - 0.000000(0) = 0.000000(0) = 0.000000 = 0.00000 = 0.0000 = 0.000 = 0.00 = 0.0

    and by the way, all of the above values are stored in FP as 0.00E+00

    In QA

    if 0        = 0.00 print 'yes' else print 'no'

    if 0.0      = 0.00 print 'yes' else print 'no'

    if 0.00     = 0.00 print 'yes' else print 'no'

    if 0.000    = 0.00 print 'yes' else print 'no'

    if 0.0000   = 0.00 print 'yes' else print 'no'

    if 0.00000  = 0.00 print 'yes' else print 'no'

    if 0.000000 = 0.00 print 'yes' else print 'no'

    if CAST(1/3 as money) = CAST(1/3 as decimal(12,6)) print 'yes' else print 'no'

    if (CAST(1/3 as money) - CAST(1/3 as decimal(12,6))) = 0 print 'yes' else print 'no'

    if (CAST(1/3 as money) - CAST(1/3 as decimal(12,6))) = 0.00 print 'yes' else print 'no'

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

  • David, so boring!

    I said money, not int.

    I said decimal(12,6), not int.

    Go to programming courses and learn how to declare variables and assing values to it.

    _____________
    Code for TallyGenerator

  • Hi Cath

    You're absolutely right on every point. It does however happen, and not only on this thread, where I would hope that a casual browser would see it as an extreme case. In the workplace, if a developer is shown to be rude or plain wrong, they're likely to be shown the door - that's exactly how I got this placement, my predecessor was both. A forum is different. Kick someone out for being antisocial and they can re-register in seconds under a different name.

    There's no single answer because there's no single problem. Fairly recently an OP received an exceptionally rude and condescending first reply and responded with "x, go blow yourself" - this was rapidly followed up with a trail of useful material from other regular posters which solved her query the same day. I haven't seen any postings by x since - but the OP has remained active. On the other hand there are one or two regular contributors to the forum who post a sentence or two of suggestions, never any code, without ever testing their ideas. Given the choice I'd take a correct answer delivered condescendingly over a misleading one delivered politely, every time. It shouldn't happen, but it does.

    I guess it's up to us to respond in the most appropriate manner when someone breaks the unwritten rules, and from where I'm sitting (250 miles south of you), David, David, Noel and Lynn are doing an admiral job with commendable restraint.

    Just my 1p worth...no need for rounding :o)

    “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

Viewing 15 posts - 256 through 270 (of 377 total)

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