Home All Groups Group Topic Archive Search About

Problem - Division between floating numbers

Author
5 Jan 2006 5:52 PM
juanca
Hi, I have a problem to divide two numbers type float, and for 100.
The problem is it to use the function the ROUND in the result.

The example is the next:

declare @m1 float
declare @m2 float
declare @w1 float
declare @w2 float
declare @acumulado float
declare @division float
declare @result float
declare @decimales tinyint
declare @truncar tinyint
declare @cien float
set @m1 = 14.75
set @m2 = 14.38
set @w1 = 50
set @w2 = 50
set @decimales = 2
set @truncar = 0
set @acumulado = @m1*@w1
set @acumulado = @acumulado + @m2*@w2 
set @division = @acumulado / 100
set @result = ROUND(@division,@decimales,@truncar)
select @result

set @result = ROUND(@division,@decimales,@truncar) :

If variable @division is 15,565, with the @decimales = 2 and @truncar =0
the variable @result is 15,56.

If set @division = @acumulado / 99.99999, the @result = 15,57

Please help me about it

thanks you...
juanca

Author
5 Jan 2006 5:57 PM
Aaron Bertrand [SQL Server MVP]
Can you use DECIMAL instead of FLOAT?  FLOAT is approximated, so you can not
rely on it for precise calculations.




Show quote
"juanca" <jua***@discussions.microsoft.com> wrote in message
news:850E8221-834C-4EC9-9F8A-6F1A19B31BBB@microsoft.com...
> Hi, I have a problem to divide two numbers type float, and for 100.
> The problem is it to use the function the ROUND in the result.
>
> The example is the next:
>
> declare @m1 float
> declare @m2 float
> declare @w1 float
> declare @w2 float
> declare @acumulado float
> declare @division float
> declare @result float
> declare @decimales tinyint
> declare @truncar tinyint
> declare @cien float
> set @m1 = 14.75
> set @m2 = 14.38
> set @w1 = 50
> set @w2 = 50
> set @decimales = 2
> set @truncar = 0
> set @acumulado = @m1*@w1
> set @acumulado = @acumulado + @m2*@w2
> set @division = @acumulado / 100
> set @result = ROUND(@division,@decimales,@truncar)
> select @result
>
> set @result = ROUND(@division,@decimales,@truncar) :
>
> If variable @division is 15,565, with the @decimales = 2 and @truncar =0
> the variable @result is 15,56.
>
> If set @division = @acumulado / 99.99999, the @result = 15,57
>
> Please help me about it
>
> thanks you...
> juanca

AddThis Social Bookmark Button