/** * Check whether this value is equal to the BigDecimal supplied. * * @param number * The BigDecimal to check for equality * @return true if the BigDecimal representation of the value is equal to number. */ public boolean isEqualTo( BigDecimal number ) { return getBigNumber().equals( number ); }
Value v = (Value) Context.jsToJava( value, Value.class ); if ( !v.isNull() ) { return v.getBigNumber(); } else { return null;
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; }
getBigNumber().setScale( level, BigDecimal.ROUND_FLOOR ); } else if ( isNumber() ) { double pow = Math.pow( 10, level );
if ( getBigNumber() == null ) { dos.writeInt( -1 ); // -1 == null string } else { String string = getBigNumber().toString(); dos.writeInt( string.length() ); dos.writeChars( string );
if ( getBigNumber() == null ) { dos.writeInt( -1 ); // -1 == null big number } else { String string = getBigNumber().toString(); dos.writeInt( string.length() ); dos.writeChars( string );
public Value minus( Value v ) throws KettleValueException { switch ( getType() ) { case VALUE_TYPE_BIGNUMBER: value.setBigNumber( getBigNumber().subtract( v.getBigNumber() ) ); break; case VALUE_TYPE_NUMBER: value.setNumber( getNumber() - v.getNumber() ); break; case VALUE_TYPE_INTEGER: value.setInteger( getInteger() - v.getInteger() ); break; case VALUE_TYPE_BOOLEAN: case VALUE_TYPE_STRING: default: throw new KettleValueException( "Subtraction can only be done with numbers!" ); } return this; }
if ( getBigNumber() != null ) { hash ^= getBigNumber().hashCode();
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; }
public Value divide( Value v ) throws KettleValueException { if ( isNull() || v.isNull() ) { setNull(); } else { switch ( getType() ) { case VALUE_TYPE_BIGNUMBER: setValue( getBigNumber().divide( v.getBigNumber(), BigDecimal.ROUND_HALF_UP ) ); break; case VALUE_TYPE_NUMBER: setValue( getNumber() / v.getNumber() ); break; case VALUE_TYPE_INTEGER: setValue( getInteger() / v.getInteger() ); break; case VALUE_TYPE_BOOLEAN: case VALUE_TYPE_STRING: default: throw new KettleValueException( "Division can only be done with numeric data!" ); } } return this; }
public Value plus( Value v ) { switch ( getType() ) { case VALUE_TYPE_BIGNUMBER: setValue( getBigNumber().add( v.getBigNumber() ) ); break; case VALUE_TYPE_NUMBER: setValue( getNumber() + v.getNumber() ); break; case VALUE_TYPE_INTEGER: setValue( getInteger() + v.getInteger() ); break; case VALUE_TYPE_BOOLEAN: setValue( getBoolean() | v.getBoolean() ); break; case VALUE_TYPE_STRING: setValue( getString() + v.getString() ); break; default: break; } 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 ); return getBigNumber().compareTo( v.getBigNumber() );
int cmp = getBigNumber().compareTo( new BigDecimal( 0L ) ); if ( cmp > 0 ) { value.setBigNumber( new BigDecimal( 1L ) );
} else if ( isBigNumber() || v.isBigNumber() ) { setValue( ValueDataUtil.multiplyBigDecimals( getBigNumber(), v.getBigNumber(), null ) ); } else if ( isNumber() || v.isNumber() ) {
/** * Convert this Value from type String to another type * * @param newtype * The Value type to convert to. */ public void convertString( int newtype ) throws KettleValueException { switch ( newtype ) { case VALUE_TYPE_STRING: break; case VALUE_TYPE_NUMBER: setValue( getNumber() ); break; case VALUE_TYPE_DATE: setValue( getDate() ); break; case VALUE_TYPE_BOOLEAN: setValue( getBoolean() ); break; case VALUE_TYPE_INTEGER: setValue( getInteger() ); break; case VALUE_TYPE_BIGNUMBER: setValue( getBigNumber() ); break; default: throw new KettleValueException( "Please specify the type to convert to from String type." ); } }
return value.getBoolean(); case ValueMetaInterface.TYPE_BIGNUMBER: return value.getBigNumber(); case ValueMetaInterface.TYPE_BINARY: return value.getBytes();
if ( getBigNumber() == null ) { setValue( other.getBigNumber() );