Why don't you "want to split the string and then hide the individual strings into numbers and then divide them by the result"?
I don't know any built-in function to do this, so the simplest solution is:
double parse(String ratio) { if (ratio.contains("/")) { String[] rat = ratio.split("/"); return Double.parseDouble(rat[0]) / Double.parseDouble(rat[1]); } else { return Double.parseDouble(ratio); } }
It also covers the case where you have an integer representation of a relationship
parse("1/2") => 0.5 parse("3/7") => 0.42857142857142855 parse("1") => 1.0
mishadoff
source share