Is there any way to get Java to output a number as a fraction rather than a decimal.

For example if you asked it to display the result of (2/3) + (5/3), could you have it display the answer as 7/3 rather than 2.3333333333...?

Re: Is there any way to get Java to output a number as a fraction rather than a decim

There is nothing in the standard Java libraries to handle rational arithmetic. But there must be millions of examples of a Rational class a google away (it's a very common programming exercise), or you could write your own.

Re: Is there any way to get Java to output a number as a fraction rather than a decim

Even if you only have a double value 0.dddd ... (ignoring the integer part), it can be written as a fraction 10000 ... / dddd ... which can be simplified to (10000 .../gcd)/dddd .../gcd) where gcd is the greates common divisor of the numerator and denominator (there exist more advanced methods to find irreducable numerators and denominators).

kind regards,

Jos