public static long castToLong(String s) {
    if (s == null) return 0;

    if (s.equals("INF") || s.equals("-INF") || s.equals("NaN"))
      throw new ArithmeticException("'" + s + "' is too large for long.");

    s = s.trim();
    java.lang.StringBuffer buf = new java.lang.StringBuffer();
    switch (prepareNumber(buf, s)) {
      case 1:
        return Long.parseLong(buf.toString());
      case 2:
        return new BigDecimal(buf.toString()).longValue();
      case 3:
        return (long) Double.parseDouble(buf.toString());
      default:
        throw new NumberFormatException("'" + s + "' cannot be converted to long.");
    }
  }
 public long toLong() {
   int dot = mantissa.indexOf('.');
   if (dot >= 0) return Long.parseLong(sign + mantissa.substring(0, dot));
   else return Long.parseLong(sign + mantissa);
 }