pentaho/pentaho-kettle · error · KettleValueException

Function ROUND only works with a number

Error message

Function ROUND only works with a number

What it means

Thrown by the no-argument Value.round() when the value is not numeric. The function computes Math.round(getNumber()) and only accepts numeric types; anything else raises KettleValueException. ROUND has no meaning for strings, dates, or booleans in this API.

Solutions

  1. Verify value.isNumeric() before calling round().
  2. Re-type the field to Number/Integer in the input step or a 'Select values' step.
  3. Parse the string to a number first if the data is genuinely numeric but string-typed.
  4. Catch KettleValueException and handle non-numeric rows explicitly.

Example fix

// before
Value r = value.round(); // throws when value is String
// after
Value r = value.isNumeric() ? value.round() : new Value(value.getName(), Double.parseDouble(value.getString()));
Defensive patterns

Strategy: type-guard

Validate before calling

if (!value.isNumeric()) { throw new IllegalArgumentException(value.getName() + " must be numeric before ROUND"); }

Type guard

boolean roundSafe(Value v) { return v != null && v.isNumeric(); }

Try / catch

try { result = value.round(); } catch (KettleValueException e) { result = null; }

Prevention

When it happens

Trigger: Calling value.round() (ROUND function) on a Value typed as String, Date, Boolean, or Binary.

Common situations: Rounding a column that was read as String from a text file; a previous transformation step converted the number to a formatted String; using ROUND on a Boolean flag.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/4b748f0607b63860. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:2714

    return this;
  }

  /**
   * Rounds off to the nearest integer.
   * <p>
   * See also: java.lang.Math.round()
   *
   * @return The rounded Number value.
   */
  public Value round() throws KettleValueException {
    if ( isNull() ) {
      return this;
    }

    if ( isNumeric() ) {
      setValue( (double) Math.round( getNumber() ) );
    } else {
      throw new KettleValueException( "Function ROUND 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() ) {

View on GitHub (pinned to f3058517a1)