code: public double toDouble(Object val) {
      if (val == null) {
        return 0;
      }
      else if (val instanceof Double) {
        return ((Double) val).doubleValue();
      }
      else if (val instanceof Number) {
        // The below construct is used rather than ((Number)val).doubleValue() to ensure
        // equality between comparing new Double( 6.4 / 3 ) and the stencil expression of 6.4 / 3
        return Double.parseDouble(String.valueOf(val));
      }
      else if (val instanceof Boolean) {
        return ((Boolean) val).booleanValue() ? 1. : 0.;
      }
      else if (val instanceof String) {
        String string = ((String) val).trim();
        if ("".equals(string)) {
          return Double.NaN;
        }
        else {
          // the spec seems to be iffy about this. Going to give it a wack anyway
          return Double.parseDouble(string);
        }
      }
      else if (val instanceof Character) {
        int i = ((Character) val).charValue();
        return i;
      }
  
      throw new ArithmeticException("Double coercion: " + val.getClass().getName() + ":(" + val + ")");
    }
docs: Coerce to a double.
  
  @param val
  Object to be coerced.
  @return The double coerced value.
  @throws NullPointerException
  if val is null and mode is strict.