/** * Checks whether or not this Value is Numeric A Value is numeric if it is either of type Number or Integer * * @return true if the value is either of type Number or Integer */ public boolean isNumeric() { return isInteger() || isNumber() || isBigNumber(); }
public Value trunc() throws KettleValueException { if ( isNull() ) { return this; // don't do anything, leave it at NULL! } if ( isInteger() ) { // Nothing return this; } if ( isBigNumber() ) { getBigNumber().setScale( 0, BigDecimal.ROUND_FLOOR ); } else if ( isNumber() ) { setValue( Math.floor( getNumber() ) ); } else if ( isDate() ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() ); cal.set( Calendar.MILLISECOND, 0 ); cal.set( Calendar.SECOND, 0 ); cal.set( Calendar.MINUTE, 0 ); cal.set( Calendar.HOUR_OF_DAY, 0 ); setValue( cal.getTime() ); } else { throw new KettleValueException( "Function TRUNC only works on numbers and dates" ); } return this; }
return this; // nothing to do. if ( isBigNumber() ) { getBigNumber().setScale( level, BigDecimal.ROUND_FLOOR ); } else if ( isNumber() ) {
public Value abs() throws KettleValueException { if ( isNull() ) { return this; } if ( isBigNumber() ) { setValue( getBigNumber().abs() ); } else if ( isNumber() ) { setValue( Math.abs( getNumber() ) ); } else if ( isInteger() ) { setValue( Math.abs( getInteger() ) ); } else { throw new KettleValueException( "Function ABS only works with a number" ); } return this; }
/** * Rounds the Number value to a certain number decimal places. * * @param decimalPlaces * @return The rounded Number Value * @throws KettleValueException * in case it's not a number (or other problem). */ public Value round( int decimalPlaces ) throws KettleValueException { if ( isNull() ) { return this; } if ( isNumeric() ) { if ( isBigNumber() ) { // Multiply by 10^decimalPlaces // For example 123.458343938437, Decimalplaces = 2 // BigDecimal bigDec = getBigNumber(); // System.out.println("ROUND decimalPlaces : "+decimalPlaces+", bigNumber = "+bigDec); bigDec = bigDec.setScale( decimalPlaces, BigDecimal.ROUND_HALF_EVEN ); // System.out.println("ROUND finished result : "+bigDec); setValue( bigDec ); } else { setValue( Const.round( getNumber(), decimalPlaces ) ); } } else { throw new KettleValueException( "Function ROUND only works with a number" ); } return this; }
isNull() || ( isString() && ( getString() == null || getString().length() == 0 ) ) || ( isDate() && getDate() == null ) || ( isBigNumber() && getBigNumber() == null ); boolean n2 = v.isNull() || ( v.isString() && ( v.getString() == null || v.getString().length() == 0 ) ) || ( v.isDate() && v.getDate() == null ) || ( v.isBigNumber() && v.getBigNumber() == null );
} else if ( isBigNumber() || v.isBigNumber() ) {