{"record":{"id":"4b748f0607b63860","repo":"pentaho/pentaho-kettle","slug":"function-round-only-works-with-a-number","errorCode":null,"errorMessage":"Function ROUND only works with a number","messagePattern":"Function ROUND only works with a number","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":2714,"sourceCode":"    return this;\n  }\n\n  /**\n   * Rounds off to the nearest integer.\n   * <p>\n   * See also: java.lang.Math.round()\n   *\n   * @return The rounded Number value.\n   */\n  public Value round() throws KettleValueException {\n    if ( isNull() ) {\n      return this;\n    }\n\n    if ( isNumeric() ) {\n      setValue( (double) Math.round( getNumber() ) );\n    } else {\n      throw new KettleValueException( \"Function ROUND only works with a number\" );\n    }\n    return this;\n  }\n\n  /**\n   * Rounds the Number value to a certain number decimal places.\n   *\n   * @param decimalPlaces\n   * @return The rounded Number Value\n   * @throws KettleValueException\n   *           in case it's not a number (or other problem).\n   */\n  public Value round( int decimalPlaces ) throws KettleValueException {\n    if ( isNull() ) {\n      return this;\n    }\n\n    if ( isNumeric() ) {","sourceCodeStart":2696,"sourceCodeEnd":2732,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L2696-L2732","documentation":"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.","triggerScenarios":"Calling value.round() (ROUND function) on a Value typed as String, Date, Boolean, or Binary.","commonSituations":"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.","solutions":["Verify value.isNumeric() before calling round().","Re-type the field to Number/Integer in the input step or a 'Select values' step.","Parse the string to a number first if the data is genuinely numeric but string-typed.","Catch KettleValueException and handle non-numeric rows explicitly."],"exampleFix":"// before\nValue r = value.round(); // throws when value is String\n// after\nValue r = value.isNumeric() ? value.round() : new Value(value.getName(), Double.parseDouble(value.getString()));","handlingStrategy":"type-guard","validationCode":"if (!value.isNumeric()) { throw new IllegalArgumentException(value.getName() + \" must be numeric before ROUND\"); }","typeGuard":"boolean roundSafe(Value v) { return v != null && v.isNumeric(); }","tryCatchPattern":"try { result = value.round(); } catch (KettleValueException e) { result = null; }","preventionTips":["Verify field type metadata after any Select values step","Don't format numbers to Strings before further math","Use isNumeric() guards in JavaScript/formula steps"],"tags":["kettle","type-mismatch","rounding"],"backgroundTag":"type-mismatch","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}