Results 1 to 3 of 3

Thread: division

  1. #1
    Join Date
    Sep 2010

    Smile Unanswered: division


    i am dividing 3 by 2 or 1 by 2..then i am not getting desired result. How do i get it?..

    for example :-

    3/2 = 1.5

    1/2 = 0.5..

    how do i get?


  2. #2
    Join Date
    Sep 2010

    Smile thanks guys :)

    select convert(float, 1)/convert(float, 2)

    this query works for me


  3. #3
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    In the expression 3/2 the 3 is interpreted as an integer and the 2 is too, so the result of the division produced by SQL Server will be the integer dividend which is 1 (another integer).

    In the expression 3.0/2 the 3.0 is a NUMERIC(5, 2) and the 2 is an integer, so the result of the division provided by SQL Server is 1.5 which is also a NUMERIC(5, 2).

    Datatypes are important to understand, especially in numeric expressions!

    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts