Arithmetic Operation Results

  • rcaro

    SSC Enthusiast

    Points: 102

    Comments posted to this topic are about the item Arithmetic Operation Results

  • Malcolm Wynden

    Say Hey Kid

    Points: 676

    [font="Courier New"]select 100 / (100 / 108)[/font]

    is a similar example that yields "Divide by zero error encountered" - a strange backdoor to getting this error.txtPost_CommentEmoticon(';-)');

  • Koen Verbeeck

    SSC Guru

    Points: 258955

    Easy one. Been bitten by integer division many, many times.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Ed Wagner

    SSC Guru

    Points: 286960

    Koen Verbeeck (5/27/2015)


    Easy one. Been bitten by integer division many, many times.

    Agreed on both points. Integer division can also be used to your advantage, but that article isn't published yet.

  • This was removed by the editor as SPAM

  • Koen Verbeeck

    SSC Guru

    Points: 258955

    Ed Wagner (5/27/2015)


    Koen Verbeeck (5/27/2015)


    Easy one. Been bitten by integer division many, many times.

    Agreed on both points. Integer division can also be used to your advantage, but that article isn't published yet.

    It's quite useful when you don't need the remainder of the division, indeed.

    In all other cases, it's just extremely frustrating 😀

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Revenant

    SSC-Forever

    Points: 42467

    Really easy - I am (almost) ashamed that I got a full point...

    Thanks, Remberto!

  • SQL_Hunt

    SSC-Dedicated

    Points: 33277

    Fairly simple. Scored 1 mark.

    Thanks.

  • akljfhnlaflkj

    SSC Guru

    Points: 76202

    Yep, an easy one. I've dealt with this before.

  • brdudley

    SSCrazy

    Points: 2268

    Koen Verbeeck (5/27/2015)


    It's quite useful when you don't need the remainder of the division, indeed.

    In all other cases, it's just extremely frustrating 😀

    +1

    When it's needed, it should be accompanied by a comment.

    I'm learning Python which has "floor" division of integers. That takes some getting used to. It differs from integer division on the treatment of negative numbers.

  • DonlSimpson

    SSCertifiable

    Points: 6774

    It's nice to have a question I can do in my head once in a while.

    Don Simpson



    I'm not sure about Heisenberg.

  • John Hanrahan

    Hall of Fame

    Points: 3825

    Um, you didn't say in SQL!! Good question, I knew the answer but just like doing the math in my head. 😀

  • rcaro

    SSC Enthusiast

    Points: 102

    If the question has a 'select' statement is SQL. Cheers:-)

  • Bhushan Kulkarni

    SSCrazy

    Points: 2829

    Simple One 🙂

  • DataTherapist

    Mr or Mrs. 500

    Points: 510

    Say WHAT?!?

    Apparently I have NOT been around the block enough times, because this was new to me.

    I would have not suspected that 1/2 is NOT .5....!

    No small wonder that folks get bitten on this. It is just not what you expect.

    If I'm dealing with a variable that I've declared, then I think I might have a chance of being more aware of how the datatype would affect the math...

    I just had to do some testing.

    SQL2008R2:

    select CAST(100 AS Decimal)/CAST(200 AS Decimal) --> 0.5000000000000000000

    select CAST(100 AS Decimal)/200 --> .5000000

    select 100/CAST(200 AS Decimal) --> 0.5000000000000000000

    select CAST(100 AS float)/CAST(200 AS Decimal) --> 0.5 interesting...

    select 100.0/200 --> .5000000

    select 100/200 --> 0

    select 108/100 --> 1

    hmmmm....

Viewing 15 posts - 1 through 15 (of 21 total)

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