int (String in) { int len = in.length(); int i = 0; boolean decSeen = false; boolean signSeen = false; int decPt = 0; char c; int nLeadZero = 0; int nTrailZero= 0; skipLeadingZerosLoop: while (i < len) { c = in.charAt(i); if (c == '0') { nLeadZero++; } else if (c == '.') { if (decSeen) { // already saw one ., this is the 2nd. throw new NumberFormatException("multiple points"); } decPt = i; if (signSeen) { decPt -= 1; } decSeen = true; } else { break skipLeadingZerosLoop; } i++; } return decPt; }