Arithmetic Operation Results

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

  • [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(';-)');

  • 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

  • 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

  • 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

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

    Thanks, Remberto!

  • Fairly simple. Scored 1 mark.

    Thanks.

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

  • 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.

  • 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.

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

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

  • Simple One 🙂

  • 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 20 total)

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