commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mikkel Meyer Andersen <m...@mikl.dk>
Subject Re: Math - Fractions 3/2 to 1 1/2
Date Tue, 23 Nov 2010 14:18:33 GMT
Try to look at FractionFormat.getProperInstance(). Example:
            System.out.println(FractionFormat.getProperInstance().format(new
Fraction(5, 2)));
            System.out.println(FractionFormat.getImproperInstance().format(new
Fraction(5, 2)));
            System.out.println(FractionFormat.getProperInstance().format(new
Fraction(2, 5)));
            System.out.println(FractionFormat.getImproperInstance().format(new
Fraction(2, 5)));

2010/11/23 paulbeuk <paul.van.beukering@gmail.com>:
>
> Hello sebb-2-2
>
>> See http://commons.apache.org/math/userguide/fraction.html
>
> I have red that page, but can not find the answer to my question there. Can
> you be more specific?
>
> FractionFormat format = new FractionFormat();
> Fraction f = new Fraction(4, 2);
> String s = format.format(f);
> I want the outcome is human readable as possible, so 2 and not "4 / 2"
>
>
> Fraction f = new Fraction(3, 2);
> should give me 1 1/2 and not "3 / 2"
>
> tia
> --
> View this message in context: http://apache-commons.680414.n4.nabble.com/Math-Fractions-3-2-to-1-1-2-tp3055391p3055433.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message