Saturday, August 27, 2005

float data type are not for monetary calculation. use decimal

set nocount on

select totF = 10.21 - 10.2, totD = convert(float, 10.21) - 10.2

declare @t table
(
f float,
d decimal(10,2)
)


declare @i integer
set @i = 0
while @i < 10
insert into @t(f,d) select 0.1, 0.1
set @i = @i + 1
end

select sumF = sum(f), sumD = sum(d) from @t

set nocount off

--------------------------------------------

totF
.01
totD 1.0000000000001563E-2


sumF
0.99999999999999989
sumD 1.00

0 Comments:

Post a Comment

<< Home