1. Registered User
Join Date
Sep 2010
Posts
153

Hi..

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?

Thanks

2. Registered User
Join Date
Sep 2010
Posts
153

## thanks guys :)

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

this query works for me

thanks

3. Resident Curmudgeon
Join Date
Feb 2004
Location
In front of the computer
Posts
15,579
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!

-PatP

#### Posting Permissions

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