Reputation: 31795
I'm working with a recipe database application and I need the ability to convert natural language strings to numbers and vice versa. For example, I need 1 1/4 to convert to 1.25, and I'll need to be able to convert 1.25 back into 1 1/4.
Is there any library or built-in functions that can do this?
Upvotes: 1
Views: 711
Reputation: 1686
None that I know of in the Java libraries, but there are some online.
Apache has a Fraction class. Here's it's API http://commons.apache.org/math/apidocs/org/apache/commons/math/fraction/Fraction.html
The constructor Fraction(double value)
, Fraction(int num, int den)
, and the methods add(Fraction fraction)
and doubleValue()
are what you want, I think.
Upvotes: 1