/** * 分析格式为#,##0.00格式的字符串 */ public static BigDecimal parsePrettyString(String numberStr) throws ParseException { return new BigDecimal(PRETTY_FORMAT.get().parse(numberStr).doubleValue()); }
/** * 分析格式为0.00格式的字符串 */ public static BigDecimal parseString(String numberStr) throws ParseException { return new BigDecimal(DEFAULT_FORMAT.get().parse(numberStr).doubleValue()); }
/** * 按格式分析字符串,当pattern为空时,pattern默认为#,##0.00 */ public static BigDecimal parseString(String numberStr, String pattern) throws ParseException { DecimalFormat df = null; if (StringUtils.isEmpty(pattern)) { df = PRETTY_FORMAT.get(); } else { df = (DecimalFormat) DecimalFormat.getInstance(); df.applyPattern(pattern); } return new BigDecimal(df.parse(numberStr).doubleValue()); } }
/** {@inheritDoc} */ @Override public BigDecimal getBigDecimal(int colIdx) throws SQLException { Object val = getValue(colIdx); if (val == null) return null; Class<?> cls = val.getClass(); if (cls == BigDecimal.class) return (BigDecimal)val; else if (val instanceof Number) return new BigDecimal(((Number)val).doubleValue()); else if (cls == Boolean.class) return new BigDecimal((Boolean)val ? 1 : 0); else if (cls == String.class || cls == Character.class) { try { return (BigDecimal)decimalFormat.get().parse(val.toString()); } catch (ParseException e) { throw new SQLException("Cannot convert to BigDecimal: " + val, SqlStateCode.CONVERSION_FAILED, e); } } else throw new SQLException("Cannot convert to BigDecimal: " + val, SqlStateCode.CONVERSION_FAILED); }
/** {@inheritDoc} */ @Override public BigDecimal getBigDecimal(int colIdx) throws SQLException { Object val = getValue(colIdx); if (val == null) return null; Class<?> cls = val.getClass(); if (cls == BigDecimal.class) return (BigDecimal)val; else if (val instanceof Number) return new BigDecimal(((Number)val).doubleValue()); else if (cls == Boolean.class) return new BigDecimal((Boolean)val ? 1 : 0); else if (cls == String.class || cls == Character.class) { try { return (BigDecimal)decimalFormat.get().parse(val.toString()); } catch (ParseException e) { throw new SQLException("Cannot convert to BigDecimal: " + val, SqlStateCode.CONVERSION_FAILED, e); } } else throw new SQLException("Cannot convert to BigDecimal: " + val, SqlStateCode.CONVERSION_FAILED); }
private int determineDepth( String depthString ) throws KettleException { DecimalFormat df = new DecimalFormat( "0" ); ParsePosition pp = new ParsePosition( 0 ); df.setParseIntegerOnly( true ); try { Number n = df.parse( depthString, pp ); if ( n == null ) { return 1; // default } if ( pp.getErrorIndex() == 0 ) { throw new KettleException( "Unable to convert stored depth '" + depthString + "' to depth at position " + pp.getErrorIndex() ); } return n.intValue(); } catch ( Exception e ) { throw new KettleException( "Unable to convert stored depth '" + depthString + "' to depth", e ); } }
return formatter.parse((String) value);
return formatter.parse((String) value);
dRC = ( formatter.parse( Const.ltrim( sArg1 ) ) ).doubleValue(); } catch ( Exception e ) { throw new RuntimeException( "Could not convert the given String : " + e.getMessage() ); dRC = ( formatter.parse( sArg1 ) ).doubleValue(); return new Double( dRC ); } catch ( Exception e ) { DecimalFormatSymbols dfs = new DecimalFormatSymbols( EnvUtil.createLocale( sArg3.toLowerCase() ) ); DecimalFormat formatter = new DecimalFormat( sArg2, dfs ); dRC = ( formatter.parse( sArg1 ) ).doubleValue(); return new Double( dRC );
protected synchronized Long convertStringToInteger( String string ) throws KettleValueException { string = Const.trimToType( string, getTrimType() ); // see if trimming needs // to be performed before // conversion if ( Utils.isEmpty( string ) ) { return null; } try { Number number; if ( lenientStringToNumber ) { number = new Long( getDecimalFormat( false ).parse( string ).longValue() ); } else { ParsePosition parsePosition = new ParsePosition( 0 ); number = getDecimalFormat( false ).parse( string, parsePosition ); if ( parsePosition.getIndex() < string.length() ) { throw new KettleValueException( toString() + " : couldn't convert String to number : non-numeric character found at position " + ( parsePosition.getIndex() + 1 ) + " for value [" + string + "]" ); } } return new Long( number.longValue() ); } catch ( Exception e ) { throw new KettleValueException( toString() + " : couldn't convert String to Integer", e ); } }
protected synchronized Double convertStringToNumber( String string ) throws KettleValueException { string = Const.trimToType( string, getTrimType() ); // see if trimming needs // to be performed before // conversion if ( Utils.isEmpty( string ) ) { return null; } try { DecimalFormat format = getDecimalFormat( false ); Number number; if ( lenientStringToNumber ) { number = format.parse( string ); } else { ParsePosition parsePosition = new ParsePosition( 0 ); number = format.parse( string, parsePosition ); if ( parsePosition.getIndex() < string.length() ) { throw new KettleValueException( toString() + " : couldn't convert String to number : non-numeric character found at position " + ( parsePosition.getIndex() + 1 ) + " for value [" + string + "]" ); } } return new Double( number.doubleValue() ); } catch ( Exception e ) { throw new KettleValueException( toString() + " : couldn't convert String to number ", e ); } }
DecimalFormat df = new DecimalFormat(); df.setParseBigDecimal(true); maxBigDecimalValue = (BigDecimal) df.parse(maxValueString);
if (rank == 0) { try { newArr.addi((format.parse(entries[0])).doubleValue()); } catch (ParseException e) { e.printStackTrace(); for (int i = 0; i < theShape[rank - 1]; i++) { try { BigDecimal number = (BigDecimal) format.parse(entries[i]); subsetArr[i] = number.doubleValue(); } catch (ParseException e) {
return df.parse( value ).doubleValue(); } catch ( Exception e ) { String message = "Couldn't convert string to number " + e.toString();
dRC = ( formatter.parse( Const.ltrim( sArg1 ) ) ).doubleValue(); } catch ( Exception e ) { throw Context.reportRuntimeError( "Could not convert the given String : " + e.getMessage() ); dRC = ( formatter.parse( sArg1 ) ).doubleValue(); return new Double( dRC ); } catch ( Exception e ) { DecimalFormatSymbols dfs = new DecimalFormatSymbols( EnvUtil.createLocale( sArg3.toLowerCase() ) ); DecimalFormat formatter = new DecimalFormat( sArg2, dfs ); dRC = ( formatter.parse( sArg1 ) ).doubleValue(); return new Double( dRC );
public synchronized void start() { if (isRunning) { return; } // report if checkpoint incomplete/invalid if(getRecoveryCheckpoint()!=null) { File cpDir = getRecoveryCheckpoint().getCheckpointDir().getFile(); if(!Checkpoint.hasValidStamp(cpDir)) { LOGGER.severe( "checkpoint '"+cpDir.getAbsolutePath() +"' missing validity stamp file; checkpoint data " +"may be missing or otherwise corrupt."); } this.lastCheckpoint = getRecoveryCheckpoint(); String serial = getRecoveryCheckpoint().getShortName().substring(2); try { Number lastCheckpointNumber = Checkpoint.INDEX_FORMAT.parse(serial); this.nextCheckpointNumber = lastCheckpointNumber.intValue() + 1; } catch (ParseException e) { LOGGER.warning("failed to parse serial from " + lastCheckpoint.getShortName() + " - " + e); } } this.isRunning = true; setupCheckpointTask(); }
setValue( df.parse( getString() ).doubleValue() ); } catch ( Exception e ) { String message = "Couldn't convert string to number " + e.toString();
if (BigDecimal.class.isAssignableFrom(populateValueRequest.getReturnType())) { format.setParseBigDecimal(true); format.parse(populateValueRequest.getRequestedValue(), pp); format.setParseBigDecimal(false); } else { format.parse(populateValueRequest.getRequestedValue(), pp); try { if (Double.class.isAssignableFrom(populateValueRequest.getReturnType())) { format.parse(populateValueRequest.getRequestedValue(), pp); } else { format.setParseBigDecimal(true); format.parse(populateValueRequest.getRequestedValue(), pp); format.setParseBigDecimal(false);