Skip to Main Content

Java Programming

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!

Fractions not working? 1/2 = 0.0?

807603Jan 15 2008 — edited Jan 16 2008
I've been using Java for some time, and in all this time, I've never noticed this.

I have a program that needs to be able to see the value of a fraction.

Say I have something like 45/6, which equals 7.5 in the real world. However, in Java,it lists it as being 7.0. It does this with other fractions too, like 1/3=0.0, even when I'm putting it into a float or double.

Why is it doing this and how do I fix it?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 13 2008
Added on Jan 15 2008
15 comments
465 views