Sunday, February 19, 2012

Converting to decimal

Hi all,
OK, I'm sure very simple question, what am I doing wrong.
how do I get the percentage? of 68 / 1812
@.result keeps showing 0.00
Declare @.result varchar(20)
set @.result = cast(round(100 * (68 / 1812) , 2)as numeric(5,2))
print @.result
thanks
GVMake the inner numbers decimals as the calculations happen before the
cast:
Declare @.result varchar(20)
set @.result = cast(round(100 * (68.0 / 1812.0) , 2)as numeric(5,2))
print @.result
or
Declare @.result varchar(20)
set @.result = cast(round(100 * (cast(68 as numeric(5,2)) / cast(1812 as
numeric(6,2))) , 2)as numeric(5,2))
print @.result|||Integer division = Integer result. Try casting or representing one of values
involved in the formula to numeric.
Declare @.result varchar(20)
set @.result = cast(round(100.00 * (68.00 / 1812.00) , 2)as numeric(5,2))
print @.result
AMB
"gv" wrote:

> Hi all,
> OK, I'm sure very simple question, what am I doing wrong.
> how do I get the percentage? of 68 / 1812
> @.result keeps showing 0.00
> Declare @.result varchar(20)
> set @.result = cast(round(100 * (68 / 1812) , 2)as numeric(5,2))
> print @.result
> thanks
> GV
>
>|||thanks
gv
"gv" <viatorg@.musc.edu> wrote in message
news:%23I$MWu9LFHA.3852@.tk2msftngp13.phx.gbl...
> Hi all,
> OK, I'm sure very simple question, what am I doing wrong.
> how do I get the percentage? of 68 / 1812
> @.result keeps showing 0.00
> Declare @.result varchar(20)
> set @.result = cast(round(100 * (68 / 1812) , 2)as numeric(5,2))
> print @.result
> thanks
> GV
>

No comments:

Post a Comment