don't get the decimal value when dividing int by int

don't get the decimal value when dividing int by int

Post by add » Wed, 08 May 2002 00:56:34



Hello All -

I don't seem to be getting the decimal values (real number), when
dividing the int by int. For example, when I divide 18 by 12, I get 1.
 When I divide 12 by 18, I get 0.

I have tried using cast and convert but none helped. I am posting my
simple selects as follows.

Using SQL 7 on Win2K. Any ideas ?

select  (convert(decimal(7,2),(18 / 12))) as pct_complete
select  cast(18 / 12 as numeric) as pct_complete
select  cast(18 / 12 as numeric (5,2)) as pct_complete
select  cast(18 / 12 as decimal (5,2)) as pct_complete

thanks..

addi

 
 
 

don't get the decimal value when dividing int by int

Post by LudekS » Wed, 08 May 2002 01:45:10


My SQL server is down at the moment, but I think you have to:

select cast(18 as numeric(5,2)) / cast(12 as numeric(5,2) )

In other word, cast to numeric before divide, also adjust the numeric to
precision required.

Louis


Quote:> Hello All -

> I don't seem to be getting the decimal values (real number), when
> dividing the int by int. For example, when I divide 18 by 12, I get 1.
>  When I divide 12 by 18, I get 0.

> I have tried using cast and convert but none helped. I am posting my
> simple selects as follows.

> Using SQL 7 on Win2K. Any ideas ?

> select (convert(decimal(7,2),(18 / 12))) as pct_complete
> select cast(18 / 12 as numeric) as pct_complete
> select cast(18 / 12 as numeric (5,2)) as pct_complete
> select cast(18 / 12 as decimal (5,2)) as pct_complete

> thanks..

> addi


 
 
 

don't get the decimal value when dividing int by int

Post by rl » Wed, 08 May 2002 04:33:04


select 18./12. [18/12], 12./18. [12/18]
 
 
 

1. select Year from Int where Int.Year >= p_From and Int.Year <= p_To

Is something like this possible?

For example I would like to get a recordset containing last ten
years. How?

The only way I found (no need to tell me that I'm stupid, I know
that) is :

 select Year(SYSDATE) from dual
 union
 select Year(SYSDATE)-1 from dual
 union
 ...

which is, well, next to unusable. Especialy if the range would
get bigger.

Thanks, Jenda
http://Jenda.McCann.cz (CC will be appreciated.)

2. WebSpeed compatible with version 6.3?

3. HELP: Getting parent table values who don't have corresponding child values

4. HELP ORACLE FORMS 4.5 TAB/FOLDER-VBX CONTROL

5. Converting Bytes(?) to Int / Int to Bytes

6. What do I need

7. getValueAt(int row, int column)

8. Importing Excel 4.0 -> Excel 97 to a table

9. changing Decimal datatypes to Int

10. difference between Decimal and int

11. Int vs Decimal Speed

12. Showing decimals in Int column data type

13. int type displaying as decimal - Cold Fusion