aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 9043
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]
It is sorta covered in the JavaRanch Style Guide.
subject: Java fractions
Similar Threads
confusion on (==)
Displaying Fraction with Java
java program using a class fraction
null pointer exception
What irrational fears do you have?