Division Problem

  • When run following query I'm supposed to see "1" but I simply don't

    select (3.0/23.0)+(4.0/23.0)+(7.0/23.0)+(9.0/23.0)

    Also I tried to run the following but didn't work either

    select

    (cast (3 as decimal(30,28))/cast (23 as decimal(30,28))) +

           (cast (4 as decimal(30,28))/cast (23 as decimal(30,28))) +

           (cast (7 as decimal(30,28))/cast (23 as decimal(30,28))) +

           (cast (9 as decimal(30,28))/cast (23 as decimal(30,28)))

    Any suggestions?

    Cheers

  • How about...?

    select (cast (3 as float)/cast (23 as float)) +

           (cast (4 as float)/cast (23 as float)) +

           (cast (7 as float)/cast (23 as float)) +

           (cast (9 as float)/cast (23 as float))

    /*results

    -----

    1.0

    */

    Here's a related thread - but not sure if it will help you:

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

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • Yes you are right and you are fast Thank you very much!

    I was originally using money variables when the problem pop up first and thought the decimal should solve this. I must be fooled of overwork

    Thanks again.

  • > I must be fooled of overwork

    Aren't we all!

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

Viewing 4 posts - 1 through 3 (of 3 total)

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