Sunday, March 11, 2012

division in SQL results in 0

division in SQL results in 0 Posted on: 01/09/2006 09:20:13



declare @.x int, @.y int, @.f float
set @.x = 100
set @.y = 2000
set @.f = @.x / @.y
print @.x
print @.y
print @.f

in the above code @.f prints as 0 instead of 0.05
how would i correct that?

Try this:

declare @.x int, @.y int, @.f float
set @.x = 100
set @.y = 2000
set @.f = @.x / (@.y * 1.0)
print @.x
print @.y
print @.f

No comments:

Post a Comment