What's the result?
By fmmik2x
@fmmik2x (17)
Philippines
November 20, 2008 2:50am CST
Hello,
I got a simple question, which one below gives the 50.0 result?
float constNum = 100;
float a = 0 + (50 / 100) * constNum;
float b = 1 * 50 * constNum / 100;
3 responses
@mr_mlk (364)
•
22 Nov 08
float a= 0 + (50/ 100)* constNum
(50/ 100) = 0.5, but as 50 and 100 are ints not floats this is truncated to "0".
0 + 0 * constNum = 0 + (0 * constNum) = 0 + (0 * 100) = 0 + 0 = 0
float b= 1* 50* constNum/ 100
1* 50* constNum/ 100 = (1* 50)* constNum/ 100 = 50 * constNum/ 100
50 * constNum/ 100 = (50 * constNum) / 100 = 5000 / 100
5000 / 100 = 50
1 person likes this
@Manojknair (603)
• India
20 Nov 08
I think the seccond one will give the right answer :
constNum/100=1
1*50*1=50
At one shot I feel seccond one is correct.
1 person likes this
@anjaiah_msc (3)
• India
8 Jan 09
the result is first evaluate the parnthes after that multiplication ie 0.5*100 is 50
second one is also 50