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

  • I understand, it's too hard for you to replace FLOAT with decimal, it's not what programmers suppose to do in their jobs, so I'll do it for you:

    DECLARE @One DECIMAL(12,6)

    DECLARE @Three DECIMAL(12,6)

    DECLARE @OneThirdDecimal2 DECIMAL(12,2)

    DECLARE @OneThirdDecimal6 DECIMAL(12,6)

    SET @One = 1

    SET @Three = 3

    SET @OneThirdDecimal2 = @One/@Three

    SET @OneThirdDecimal6 = @One/@Three

    SELECT @OneThirdDecimal2, @OneThirdDecimal6,

    @OneThirdDecimal2 - @OneThirdDecimal6 as ZeroDecomal6,

    CONVERT(decimal(12,2), @OneThirdDecimal2 - @OneThirdDecimal6) as ZeroDecimal2

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

    Does it change anything?

    _____________
    Code for TallyGenerator

  • wow you showed that .33 minus .333333 equals -.003333 and -.003333 rounded to 2 decimal places equals .00

    I could have done that, but what has that got to do with 1.23 minus 1.230000

    so the .33 did have four implied trailing zeroes to enable to subtraction to occur

    thank you for proving my point

    btw I have no problems with floats and decimals conversion, I use them everyday

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

  • Did you see the script?

    Did you understand it?

    I have never assigned 0.33 or 0.3333333 to any variable.

    Where did you find it?

    I assigned 1/3 to variables having different precisions.

    I showed that 1/3 with 2 decimal digits precision - 1/3 with 6 decimal digits precision equals to zero which is 0.003333 if we keep 6 decimal digits or 0.00 (same value but with 2 digits left only).

    1/3 - 1/3 = 0.003333 = 0.00

    That what is displayed by computer.

    So, if 0.00 = 0.003333 then trailing digits to be implied are "3", not "0"

    _____________
    Code for TallyGenerator

  • Did you see the script?

    Yes

    Did you understand it?

    Yes

    I have never assigned 0.33 or 0.3333333 to any variable.

    Yes you did, you assigned the rounded result of the division to the variables

    SET @OneThirdDecimal2 = @One/@Three

    is the same as

    SET @OneThirdDecimal2 = 0.33

    I assigned 1/3 to variables having different precisions.

    You cannot assign 1/3 (fraction) to a decimal variable, only the result of the division can be assigned

    I showed that 1/3 with 2 decimal digits precision - 1/3 with 6 decimal digits precision equals to zero which is 0.003333 if we keep 6 decimal digits or 0.00 (same value but with 2 digits left only).

    No you did not

    1/3 with 2 decimal digits precision - 1/3 with 6 decimal digits precision will always result in -0.003333 you cannot change that, the only thing that you can do is change the result after it is returned from the computation, as you did when you rounded it to 2 decimal places

    As for

    1/3 - 1/3 = 0.003333 = 0.00

    That what is displayed by computer.

    So, if 0.00 = 0.003333 then trailing digits to be implied are "3", not "0"

    I will not reply to this as it does not warrant one as you did not understand your own script

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

  • > You cannot assign 1/3 (fraction) to a decimal variable

    Congratulations!

    Your computer does not works with 1/3, 2/3, 1/7, 1/9, 1/11 and all other imprecise numbers.

    So, it cannot be used for scientific and statistical purposes: those values are infinite majority of all available numbers. And if you miss 100% of real world numbers nobody gonna be interested in your sandbox exercises.

    Fortunately, my computer handles imprecise values correctly, according to mathematical model using fixing precisions.

    So, anyone who needs to work out real world numbers, including 1/3 call me, not David Burrows. Because I know how to work with it, and David does not.

    > 1/3 with 2 decimal digits precision - 1/3 with 6 decimal digits precision will always result in -0.003333

    1/3 - 1/3 = 0

    Right?

    Hope you not gonna deny this.

    Value -0.003333 shows 2 things:

    1) an error created by trailing zeros added to 2 digits precise number;

    2) level of real precision of this number. It's 2 digits precision - level of the "weakest link" in our calculation.

    So, both your points were wrong:

    - trailing zeros are not implied;

    - converting to DECIMAL datatype with bigger precision does not increase precision of original number. And trailing zeros mean nothing - they are untruthful and should not be taken into consideration.

    > I will not reply to this

    No need. You have exposed enough of your ignorance.

    _____________
    Code for TallyGenerator

  • 1/3 - 1/3 = 0

    Right?

    Hope you not gonna deny this.

    No and I never did. I only stated

    0.33 - 0.333333 = -0.003333

    and

    0.33 - 0.333333 <> 0

     

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

  • Sergiy,

    Your computer does not works with 1/3, 2/3, 1/7, 1/9, 1/11 and all other imprecise numbers

    Since when have fractions been imprecise? They are simply the ratio of two integers, both of which are, by definiton, precise.

    So, it cannot be used for scientific and statistical purposes

    Being a scientist by trade, I guess I shouldn't have bought those supercomputers then. Shame that double data type can only achieve 50nm precision on the distance between the Earth and the Moon, whoops - oh so close.

    Fortunately, my computer handles imprecise values correctly

    I'm sure Intel would be interested in this impressive technology, maybe it's the new AMD cores?

    Whilst it is true that the result of rounding -0.003333 to 2 decimal places is, indeed, 0.00 (= 0 btw, implied zeros follow) there is an implied level of precision determined by the least precise operand. In this case, you are not comparing two numbers of equivalent precision and the result must therefore be constrained to the lowest level of precision.

    Bearing in mind that 1/3 cannot be represented accurately on a computer as a floating point value, there is a maximum precision defined by the IEEE754 floating point specification and assigning the same value to a floating point will result in the same representation.

    For example:

    double a = 1/3;

    double b = 1/3;

    assert(a==b);

    (Apologies for the C)

    Subsequent operation on one of those floating points may result in a loss of precision (as defined by IEEE 754) and this should be taken into account when obtaining useful output, however assuming no other operations are performed, scientifically accurate results (not to mention mathematically correct) can be obtained from floating-point arithmetic.

    Finally, whenever you consider a simple subtraction or addition (whether on computer or good ol' fashioned paper) you must perform decimal expansion in order to define the numbers correctly. A simple example: in order to perform 1 - 1.11, you must either expand 1 to 1.00 or reduce the precision of 1.11 to 1.

    Here, to obtain the correct (and accurate) answer you must increase the precision on 1 and hence we find that we have implied zeros.

  • Can you record 1/3 in a computer?

    _____________
    Code for TallyGenerator

  • > Since when have fractions been imprecise? They are simply the ratio of two integers, both of which are, by definiton, precise.

    Are you sayng you are scientist?

    Poor science.

    For those scientists who did not perform in school I explain:

    Ratio of 2 integers is an integer.

    int1 / int3 = int0. Precise ZERO.

    > I'm sure Intel would be interested in this impressive technology, maybe it's the new AMD cores?

    This technology was published before foundation of Intel.

    It was published before even foundation of USA.

    That's probably why some American "scientists" not aware of handling imprecise ratios in math.

    BTW, if an American scientist could understand the text I posted he would post a little different example:

    double a = 1/3;

    single b = 1/3;

    assert(a==b);

    What your science tell about that?

    _____________
    Code for TallyGenerator

  • yes Numerator = 1 and Denominator = 3 🙂


    * Noel

  • Noel,

    You recorder 2 values, none of them is 1/3.

    Sorry.

    _____________
    Code for TallyGenerator

  • 1 divided by 3

    As an integer (yes I know as zero as you keep on stating)

    or

    As a decimal number with a number of decimal places to a certain accuracy within the limitations of the computer, as with long hand you stop when you reach sufficient number of decimal places

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

  • So, show how 1/3 is stored in your computer?

    _____________
    Code for TallyGenerator

  • when do you guys work?

  • I was thinking the same thing 😀


    * Noel

Viewing 15 posts - 166 through 180 (of 377 total)

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