获取数字类型值

@param value 值
@param numFmtString 格式
@return 数字，可以是Double、Long
@since 4.1.0
186314
private static Number getNumberValue(String value, String numFmtString) {
		if(StrUtil.isBlank(value)) {
			return null;
		}
		double numValue = Double.parseDouble(value);
		// 普通数字
		if (null != numFmtString && numFmtString.indexOf(StrUtil.C_DOT) < 0) {
			final long longPart = (long) numValue;
			if (longPart == numValue) {
				// 对于无小数部分的数字类型，转为Long
				return longPart;
			}
		}
		return numValue;
	}
300444
public static long asLong(Object value) {
        if (value instanceof Number) {
            return ((Number) value).longValue();
        } else if (value instanceof Numeric) {
            return ((Numeric) value).asInteger();
        } else if (value instanceof Boolean) {
            return ((Boolean) value) ? 1L : 0L;
        } else if (value instanceof CharSequence) {
            try {
                return Long.parseLong(value.toString());
            } catch (NumberFormatException nfe) {
                throw new IncompatibleValueException("Unable to parse string \"" + Strings.escape(value.toString()) +
                                                     "\" to a long", nfe);
            }
        } else if (value instanceof Date) {
            // Return date timestamp.
            return ((Date) value).getTime();
        }
        throw new IncompatibleValueException("Unable to convert " + value.getClass().getSimpleName() + " to a long");

    }
333249
public static Double stringToDouble(String strString, int ibScale) throws Exception
    {
        Number objData;
        initGlobals();      // Make sure you have the utilities
        if ((strString == null) || (strString.equals(Constant.BLANK)))
            return null;
        strString = DataConverters.stripNonNumber(strString);
        try   {
            synchronized (gNumberFormat)
            {
                objData = gNumberFormat.parse(strString);
            }
            if (!(objData instanceof Double))
            {
                if (objData instanceof Number)
                    objData = new Double(objData.doubleValue());
                else
                    objData = null;
            }
        } catch (ParseException ex)   {
            objData = null;
        }
        if (objData == null)
        {
            try   {
                objData = new Double(strString);
            } catch (NumberFormatException ex)  {
                throw ex;
            }
        }
        if (ibScale != -1)
            objData = new Double(Math.floor(((Double)objData).doubleValue() * Math.pow(10, ibScale) + 0.5) / Math.pow(10, ibScale));
        return (Double)objData;
    }
540468
public void writeDouble(double value)
        throws IOException
    {
        int offset = _offset;
        byte[] buffer = _buffer;

        if (SIZE <= offset + 16) {
            flushBuffer();
            offset = _offset;
        }

        int intValue = (int) value;

        if (intValue == value) {
            if (intValue == 0) {
                buffer[offset++] = (byte) BC_DOUBLE_ZERO;

                _offset = offset;

                return;
            }
            else if (intValue == 1) {
                buffer[offset++] = (byte) BC_DOUBLE_ONE;

                _offset = offset;

                return;
            }
            else if (-0x80 <= intValue && intValue < 0x80) {
                buffer[offset++] = (byte) BC_DOUBLE_BYTE;
                buffer[offset++] = (byte) intValue;

                _offset = offset;

                return;
            }
            else if (-0x8000 <= intValue && intValue < 0x8000) {
                buffer[offset + 0] = (byte) BC_DOUBLE_SHORT;
                buffer[offset + 1] = (byte) (intValue >> 8);
                buffer[offset + 2] = (byte) intValue;

                _offset = offset + 3;

                return;
            }
        }

        int mills = (int) (value * 1000);

        if (0.001 * mills == value) {
            buffer[offset + 0] = (byte) (BC_DOUBLE_MILL);
            buffer[offset + 1] = (byte) (mills >> 24);
            buffer[offset + 2] = (byte) (mills >> 16);
            buffer[offset + 3] = (byte) (mills >> 8);
            buffer[offset + 4] = (byte) (mills);

            _offset = offset + 5;

            return;
        }

        long bits = Double.doubleToLongBits(value);

        buffer[offset + 0] = (byte) 'D';
        buffer[offset + 1] = (byte) (bits >> 56);
        buffer[offset + 2] = (byte) (bits >> 48);
        buffer[offset + 3] = (byte) (bits >> 40);
        buffer[offset + 4] = (byte) (bits >> 32);
        buffer[offset + 5] = (byte) (bits >> 24);
        buffer[offset + 6] = (byte) (bits >> 16);
        buffer[offset + 7] = (byte) (bits >> 8);
        buffer[offset + 8] = (byte) (bits);

        _offset = offset + 9;
    }
1085350
void writeString(String value) throws IOException {
        byte[] bytes = toUTF8(value);
        int size = bytes.length;
        if (size < 32) {
            output.writeByte(MIN_FIX_STR + size);
        } else if (size < 256) {
            output.writeByte(STR_8);
            output.writeByte(size);
        } else if (size < 65536) {
            output.writeByte(STR_16);
            output.writeShort(size);
        } else {
            output.writeByte(STR_32);
            output.writeInt(size);
        }
        output.write(bytes);
    }
1345213
public static Double isDouble(String value) {
		Validate.notNull(value);
		Validate.notEmpty(value);
		Double doubleValue = null;
		try{
			doubleValue = Double.parseDouble(value);
		} catch(NumberFormatException e){
			throw new TypeException("Double");
		}
		return doubleValue;
	}
1082018
public static /*@pure@*/ String doubleToString(double value, int afterDecimalPoint) {
    
    StringBuffer stringBuffer;
    double temp;
    int dotPosition;
    long precisionValue;
    
    temp = value * Math.pow(10.0, afterDecimalPoint);
    if (Math.abs(temp) < Long.MAX_VALUE) {
      precisionValue = 	(temp > 0) ? (long)(temp + 0.5) 
                                   : -(long)(Math.abs(temp) + 0.5);
      if (precisionValue == 0) {
	stringBuffer = new StringBuffer(String.valueOf(0));
      } else {
	stringBuffer = new StringBuffer(String.valueOf(precisionValue));
      }
      if (afterDecimalPoint == 0) {
	return stringBuffer.toString();
      }
      dotPosition = stringBuffer.length() - afterDecimalPoint;
      while (((precisionValue < 0) && (dotPosition < 1)) ||
	     (dotPosition < 0)) {
	if (precisionValue < 0) {
	  stringBuffer.insert(1, '0');
	} else {
	  stringBuffer.insert(0, '0');
	}
	dotPosition++;
      }
      stringBuffer.insert(dotPosition, '.');
      if ((precisionValue < 0) && (stringBuffer.charAt(1) == '.')) {
	stringBuffer.insert(1, '0');
      } else if (stringBuffer.charAt(0) == '.') {
	stringBuffer.insert(0, '0');
      }
      int currentPos = stringBuffer.length() - 1;
      while ((currentPos > dotPosition) &&
	     (stringBuffer.charAt(currentPos) == '0')) {
	stringBuffer.setCharAt(currentPos--, ' ');
      }
      if (stringBuffer.charAt(currentPos) == '.') {
	stringBuffer.setCharAt(currentPos, ' ');
      }
      
      return stringBuffer.toString().trim();
    }
    return new String("" + value);
  }
1229512
public static String format(double[][] m, NumberFormat nf) {
    return formatTo(new StringBuilder().append("[\n"), m, " [", "]\n", ", ", nf).append("]").toString();
  }
944039
private String convert(String str, String dateFormat)
    {
        String ret = str;

        // Carry out the required string conversion
        long longValue = 0L;
        double doubleValue = 0.0d;

        // Convert the input value to a number
        if(str.length() > 0)
        {
            if(inputType == INTEGER_TYPE || inputType == NUMBER_TYPE)
                longValue = Long.parseLong(str);
            else if(inputType == DECIMAL_TYPE || inputType == SECONDS_TYPE)
                doubleValue = Double.parseDouble(str);
            else if(inputType == DATETIME_TYPE && inputFormat.length() > 0)
                longValue = parseDateTime(str, inputFormat);
        }

        // Convert seconds to milliseconds
        if(inputType == SECONDS_TYPE)
            doubleValue *= 1000.0d;

        // Allow for cross type conversions
        //   eg. decimal->datetime, seconds->datetime
        if(inputType == DECIMAL_TYPE || inputType == SECONDS_TYPE)
            longValue = (long)doubleValue;
        else
            doubleValue = (double)longValue;

        // Convert the number to the output format
        if(outputType == INTEGER_TYPE)
            ret = Long.toString(longValue);
        else if(outputType == DECIMAL_TYPE || outputType == SECONDS_TYPE)
            ret = convertDecimal(doubleValue, outputFormat);
        else if(outputType == DATETIME_TYPE)
            ret = convertDateTime(longValue, 
                outputFormat.length() > 0 ? outputFormat : dateFormat);
        else if(outputType == STRING_TYPE)
            ret = convertString(str, outputFormat, regex);

        return ret;
    }
158828
public static byte[] doubleFormating(Number num, Charset charset, int fieldLength, int sizeDecimalPart) {
		int sizeWholePart = fieldLength - (sizeDecimalPart > 0 ? (sizeDecimalPart + 1) : 0);

		StringBuilder format = new StringBuilder(fieldLength);
		for (int i = 0; i < sizeWholePart-1; i++) {
			format.append("#");
		}
		if (format.length() < sizeWholePart) {
			format.append("0");
		}
		if (sizeDecimalPart > 0) {
			format.append(".");
			for (int i = 0; i < sizeDecimalPart; i++) {
				format.append("0");
			}
		}

		DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.ENGLISH);
		df.applyPattern(format.toString());
		return textPadding(df.format(num).toString(), charset, fieldLength, DBFAlignment.RIGHT,
				(byte) ' ');
	}
490331
public void setValue(int numStrings, String[] newValues) {
        value.clear();
        if (numStrings == newValues.length) {
            for (int i = 0; i < newValues.length; i++) {
                value.add(newValues[i]);
            }
        }
        else {
            Log.e(TAG, "X3D MFString setValue() numStrings not equal total newValues");
        }
    }
810517
public static final double getDouble(String value)
   {
      return (value == null || value.length() == 0 ? 0 : Double.parseDouble(value));
   }
1107705
private String formatUnits(Number value)
   {
      return (value == null ? null : m_formats.getUnitsDecimalFormat().format(value.doubleValue() / 100));
   }
468901
private static String unsignedToString(final long value) {
    if (value >= 0) {
      return Long.toString(value);
    } else {
      // Pull off the most-significant bit so that BigInteger doesn't think
      // the number is negative, then set it again using setBit().
      return BigInteger.valueOf(value & 0x7FFFFFFFFFFFFFFFL)
                       .setBit(63).toString();
    }
  }
193690
@Override
    public Long convert(Object value) {
        if (value instanceof Number) {
            double d = ((Number)value).doubleValue();
            if (Double.isNaN(d) || Math.round(d)!=d) throw new IllegalArgumentException("Not a valid long: " + value);
            return ((Number)value).longValue();
        } else if (value instanceof String) {
            return Long.parseLong((String)value);
        } else if (value instanceof Idfiable) {
            return ((Idfiable)value).longId();
        } else return null;
    }
1325347
private long parseDuration(String value) {
	        long periodMS = 0L;
	        if (value!=null) {
	            String[] parts = value.split(":");
	            for (int i = 0; i < parts.length; i++) {
	                switch (i) {
	                    case 0: // hours
	                        periodMS += (Integer.parseInt(parts[i])) * 3600000L;
	                        break;
	                    case 1: // minutes
	                        periodMS += (Integer.parseInt(parts[i])) * 60000L;
	                        break;
	                    case 2: // seconds
	                        periodMS += (Integer.parseInt(parts[i])) * 1000L;
	                        break;
	                    case 3: // ms
	                        periodMS += (Integer.parseInt(parts[i]));
	                        break;
	                    default:
	                        break;
	                }
	            }
	        }
	        return periodMS;
	    }
769395
public static int computeRawMessageSetExtensionSize(
      final int fieldNumber, final ByteString value) {
    return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2 +
           computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber) +
           computeBytesSize(WireFormat.MESSAGE_SET_MESSAGE, value);
  }