Simple math dividing
-
Hi all, I am trying to do a simple math division function. I am trying to divide 10/100. This is the line of code: double test = 10/100; I always get 0. I want to be able to get .1, what am I doing wrong? Please help!
-
Hi all, I am trying to do a simple math division function. I am trying to divide 10/100. This is the line of code: double test = 10/100; I always get 0. I want to be able to get .1, what am I doing wrong? Please help!
Hi, 10/100 is an integer expression, its value is positive and less than one, hence zero. The fact that you want to assign its value to a double is irrelevant during the evaluation. :)
Luc Pattyn [My Articles]
-
Hi all, I am trying to do a simple math division function. I am trying to divide 10/100. This is the line of code: double test = 10/100; I always get 0. I want to be able to get .1, what am I doing wrong? Please help!
So to make 10/100 result in 0.1 , U can use 10.0/100 or 10.0/100.0 as they said. But, if it is a variable like: int a=10,b=100; then U will have to typecast it like a/((double)b).
Regards, Arun Kumar.A