954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to get the result for smaller number divide larger number?

Hi All,

When I run the query:

select (100/50)

It give me "2"... good.

But when I run the query:

select (50/100)

I was expected it will give me 0.5... but it gives me 0 instead? Why? and How can I get the "0.5"?

330m
Newbie Poster
1 post since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

change the resulting variable to type double

jwshepherd
Junior Poster
123 posts since Jun 2005
Reputation Points: 20
Solved Threads: 5
 

im not too familiar with sql but i would assume it has something to do with data types maybe? for example if it was integer it would only return a whole number such as 2 or 0 in your case, im not too sure about this in sql as i dont do it but generally that could be the problem

bops
Posting Whiz in Training
214 posts since Aug 2005
Reputation Points: 23
Solved Threads: 5
 

try doing your calculations before your sql statment

Dim i As Double
Dim MySql as string 
i = 50 / 100
Mysql="Select " & i & " FROM table;"
rs.open MySQl,conn,3,3,1
jwshepherd
Junior Poster
123 posts since Jun 2005
Reputation Points: 20
Solved Threads: 5
 

Hi,

Try "select (50 * 1.0/100)" instead of "select (50/100)"

Eralper
http://www.kodyaz.com

eralper
Newbie Poster
9 posts since Aug 2005
Reputation Points: 10
Solved Threads: 2
 

or simply "select 50. / 100"

campkev
Posting Pro in Training
484 posts since Jul 2005
Reputation Points: 14
Solved Threads: 19
 

It will work fine as long as one of the numbers in division is a float or similar.
Try

select (cast(50 as float)/100)

This will work with any numeric data.

wujtehacjusz
Newbie Poster
18 posts since Mar 2007
Reputation Points: 12
Solved Threads: 7
 

oops wujtehacjusz, you may have a look at issue date;)

tesuji
Master Poster
721 posts since Apr 2008
Reputation Points: 158
Solved Threads: 98
 
oops wujtehacjusz, you may have a look at issue date;)


Damn you are right... :P

wujtehacjusz
Newbie Poster
18 posts since Mar 2007
Reputation Points: 12
Solved Threads: 7
 

the integer division is done. so the result is in integer.
try select convert(numeric(5,2), 50)/100 OR
select 50.00/100.00

sujendra
Newbie Poster
3 posts since Aug 2006
Reputation Points: 10
Solved Threads: 1
 
the integer division is done. so the result is in integer. try select convert(numeric(5,2), 50)/100 OR select 50.00/100.00


Another genius...

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You