code: protected int _countPeriods(String str)
      {
          int commas = 0;
          for (int i = 0, end = str.length(); i < end; ++i) {
              int ch = str.charAt(i);
              if (ch < '0' || ch > '9') {
                  if (ch == '.') {
                      ++commas;
                  } else {
                      return -1;
                  }
              }
          }
          return commas;
      }
docs: Helper method to find Strings of form "all digits" and "digits-comma-digits"