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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with devide/real/float

Status
Not open for further replies.

shuklix

Programmer
Jul 15, 2003
21
0
0
AU
My query is
select CAST( visits as Float)/Cast(impresions AS Float) from Table T.

visits -- Integer
impressions -- Integer and visits is always less than impressions, so visits/impressions < 1.

The value which I get is 4.8000000000000001E-2, is there
a way to see the decimal value for this ?(in this case 0.0048).

I have tried round, but had no luck with it, the result was
the same.

Thanks in Advance
Saurabh


 
Hi,

Try this.


select CAST(CAST( visits as Float)/Cast(impresions AS Float) as Numeric(10,5) )from TBL





Sunil
 
Instead of CASTing them as floats, try CASTing them as decimal(9,3) and check the results. Float is an inexact number, hence the notation. Good luck!

--Angel [rainbow]
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.
 
Declare @i int, @j int
Set @i = 4
Set @j = 7

SELECT CAST(CAST( @i as Float)/Cast(@j AS Float) as DECIMAL(10,4))

--Just specify your length and precision in the cast to decimal.

DL
MCDBA, MCSD, MCT, etc.
 
I agree with Angel. If you want the end results as DECIMAL, then start off CASTing the values as DECIMAL.

select CAST( visits as DECIMAL(6,4))/Cast(impresions AS DECIMAL(6,4)) from Table T

You just need to set the precision and scale to be the lengths you want returned.

precision = the number of digits total (both sides of decimal)
scale = the number of digits to the right of the decimal.

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top