|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Division questionWhen 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. 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 -> .00. So you do need to convert the numbers first unless you use this: Select (1.0/3.0) Hope this help. Dennis Lam Show quote "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)) -- > returns > .33 > > Is there a better way to do the division other than converting each number > to float before dividing them ? > Thank you. |
|||||||||||||||||||||||