Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

convert double to int ,,, 2 ways used but !!

807598Oct 22 2006
hi ;

I'm currently developing a small program for currency conversion, which will ask the amount in pounds then converts it to dollars with least number of notes and coins used.

most of the program is complete but im having a slight problem with converting the amount in Cent which is a double (amountCentD) to int (amountCentI) so i get rounded up value, i have used the following :

amountCentI = (int)amountCentD;

but it rounds i.e. 12.99999 to 12 and not to 13.

i have tried the following as well :

amountCentI = Math.rint(amountCentD);

but i get an error mentioning possible loss of precision.

help please ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 19 2006
Added on Oct 22 2006
0 comments
336 views