File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Java fractions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java fractions" Watch "Java fractions" New topic

Java fractions

Shirl Diva

Joined: Sep 09, 2002
Posts: 21
Does anyone know how fractions are handled in java? How would you go about those kinds of computations?
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9056
Fractions are handled with doubles by default.

double quotient = 0;
double dividend = 2 ;
double divisor = 3 ;

quotient = dividend / divisor ;

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Shirl Diva

Joined: Sep 09, 2002
Posts: 21
Thanx Marilyn. Is there a possiblity of a lose of precision - that occurs in division??
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
A few good links on this subject are mentioned in this past conversation in the Cattle Drive.
Making any sense?

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
wood burning stoves
subject: Java fractions
It's not a secret anymore!