Probem with a Real DataType

  • When I execute the next script I get and Int number instead the real.

    why?

    Also is there a way of round to 50 I mean, when I get any number x.5

    above the 0.5 round to the next int.

    declare variable aux real

    set aux=(10+72+67)/3

    print aux

    and I get 49 instead 49.666666

     

    thanks

     

  • This is because of SQL Servers datatType precedence (check out the topic in Books Online). All the numbers in your calculation are integers so it performs integer arithmetic. If you add a decimal place to one of the numbers it performs the calculation you want.

    EG:

    declare @aux real
    
    set @aux=(10.0+72+67)/3
    
    print @aux
    

    --------------------
    Colt 45 - the original point and click interface

  • Thanks Phill that's help me.

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

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