Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.304 :

Posted: Tue Apr 19, 2011 4:35 am
by ETS User
Is there an error with this question?

The solution shows 'double or float' and the explanation gives 'int,long,float or double'

Re: About Question com.enthuware.ets.scjp.v6.2.304 :

Posted: Tue Apr 19, 2011 8:18 pm
by admin
Yes, it is correct because it does not say only double or float.

Re: About Question com.enthuware.ets.scjp.v6.2.304 :

Posted: Fri Jan 24, 2014 8:30 am
by devlam
I was expecting that when giving the amount a type of float or double the real result would be given.
So 0,8. But it gives 1.0 as a result.
Only declaring rate as a float/double of casting the rate within the expression to float/double will give the real result.
I don't understand why this is.

Re: About Question com.enthuware.ets.scjp.v6.2.304 :

Posted: Fri Jan 24, 2014 9:02 am
by admin
If you have only int variables in a term, then integer operation is performed for that term. For example, in the term rate/100*1, all are ints. Therefore, it will actually return 0. If you do ((double)rate)/100*1, now you have a double in the term, so everything in that term will be promoted to a double and it will return .9.

Re: About Question com.enthuware.ets.scjp.v6.2.304 :

Posted: Sat Jan 25, 2014 8:42 am
by devlam
Strange that they implemented it that way, but now I know I can use it the right way.