0

is there an easy way to format numbers as fractions.

if user inputs "1/4in into a INCH unit value, i would like to see "1/4" instead of .25, 1/3 instead of .333333 etc..

sort of like an alias for certain select values.

is this something i can do globally in MeasureFormat?

1 Answers1

2

You can construct instances of org.jscience.mathematics.number.Rational; it's implementation of toText(), invoked by Number#toString(), may be all you need. If not, more on AmountFormat may be found here.

Rational a = Rational.valueOf(1, 4);
Rational b = Rational.valueOf(1, 3);
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045