When I do the following query:
select convert(decimal(8,2),(1/3)) -- > returns .00
When I do the following query:
select convert(decimal(8,2),convert(float,1)/convert(float,3)) -- > returns
.33
Is there a better way to do the division other than converting each number
to float before dividing them ?
Thank you.I usually do this select 1.0*1/3
http://sqlservercode.blogspot.com/|||Hi Paul,
The reason that your first SQL statement returns .00 because it treated the
number 1 and 3 as integers and "if an integer is divided by an integer, the
result is an integer that has any fractional part of the result truncated.".
Therefore, only a integer is returned for the convert function. i.e. 0 -> .0
0.
So you do need to convert the numbers first unless you use this:
Select (1.0/3.0)
Hope this help.
Dennis Lam
"Paul fpvt2" wrote:
> When I do the following query:
> select convert(decimal(8,2),(1/3)) -- > returns .00
> When I do the following query:
> select convert(decimal(8,2),convert(float,1)/convert(float,3)) -- > return
s
> .33
> Is there a better way to do the division other than converting each number
> to float before dividing them ?
> Thank you.
No comments:
Post a Comment