Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stopping rounding of numbers in SPs

Status
Not open for further replies.

DavidJA

Programmer
Jan 10, 2002
58
AU
Hey all,

consider the following code:

create table #test (Num decimal(6,2))
insert #test (num)
select 50 / 100
select * from #test


For me this returns 0.00, but 50/100 = .05 how can I make this code return 0.05.

 
could you try declaring variables of type number or decimal, set them to 50 and 100 then divide using the variables.

I don't know if this will help but it is worth a shot. Crystal
crystalized_s@yahoo.com

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

Experience is one thing you can't get for nothing.

-Oscar Wilde

 
The numbers are integer so there will be no decimal.

create table #test (Num decimal(6,2))
insert #test (num)
select convert (decimal(6,2),50) / convert (decimal(6,2),100)
select * from #test
 
Converting one of them to a decimal number will also do the trick
 
This also works

declare @temp1 decimal(6,2),
@temp2 decimal(6,2)
set @temp1=50
set @temp2=100

create table #test (Num decimal(6,2))
insert #test (num)
select @temp1 / @temp2
select * from #test

Although is admittedly a little more verbose than the other solution. Crystal
crystalized_s@yahoo.com

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

Experience is one thing you can't get for nothing.

-Oscar Wilde

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top