{"record":{"id":"9a9aef889e2f15f4","repo":"pentaho/pentaho-kettle","slug":"the-round-function-only-works-on-numeric-data","errorCode":null,"errorMessage":"The 'round' function only works on numeric data","messagePattern":"The 'round' function only works on numeric data","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/ValueDataUtil.java","lineNumber":1206,"sourceCode":"   *          Value to round\n   * @return The rounded value\n   * @throws KettleValueException\n   */\n  public static Object round( ValueMetaInterface metaA, Object dataA ) throws KettleValueException {\n    if ( dataA == null ) {\n      return null;\n    }\n\n    switch ( metaA.getType() ) {\n      case ValueMetaInterface.TYPE_NUMBER:\n        return new Double( Math.round( metaA.getNumber( dataA ).doubleValue() ) );\n      case ValueMetaInterface.TYPE_INTEGER:\n        return metaA.getInteger( dataA );\n      case ValueMetaInterface.TYPE_BIGNUMBER:\n        return new BigDecimal( Math.round( metaA.getNumber( dataA ).doubleValue() ) );\n\n      default:\n        throw new KettleValueException( \"The 'round' function only works on numeric data\" );\n    }\n  }\n\n  /**\n   * Rounding with no decimal places with a given rounding method\n   *\n   * @param metaA\n   *          Metadata of value to round\n   * @param dataA\n   *          Value to round\n   * @param roundingMode\n   *          The mode for rounding, e.g. java.math.BigDecimal.ROUND_HALF_EVEN\n   * @return The rounded value\n   * @throws KettleValueException\n   */\n  public static Object round( ValueMetaInterface metaA, Object dataA, int roundingMode ) throws KettleValueException {\n    if ( dataA == null ) {\n      return null;","sourceCodeStart":1188,"sourceCodeEnd":1224,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/ValueDataUtil.java#L1188-L1224","documentation":"The single-argument round helper rounds a value to 0 decimal places using the default rounding method, handling only Number, Integer, and BigNumber types. A non-numeric metadata type falls to the default branch and throws this KettleValueException.","triggerScenarios":"Calling ValueDataUtil.round(metaA, dataA) (Calculator 'Round( A )') when metaA.getType() is not TYPE_NUMBER, TYPE_INTEGER, or TYPE_BIGNUMBER — e.g. a String or Date field.","commonSituations":"Rounding a field that was read from a delimited file as String; a prior type conversion changed Number to String; passing a Boolean flag field into Round by mistake.","solutions":["Type the field as Number/Integer/BigNumber before the Calculator step (Select Values metadata tab).","Add an explicit string-to-number conversion step before rounding.","Null-check/type-check inputs in a UDJC step before calling round."],"exampleFix":"// before: Round(fieldX) where fieldX is String\n// after: Select Values: fieldX Type=Number, then Round(fieldX)","handlingStrategy":"type-guard","validationCode":"int t = metaA.getType();\nif (t != ValueMetaInterface.TYPE_NUMBER && t != ValueMetaInterface.TYPE_INTEGER && t != ValueMetaInterface.TYPE_BIGNUMBER) {\n  throw new KettleValueException(\"round(A) requires numeric field, got type \" + t);\n}","typeGuard":"public static boolean isNumericMeta(ValueMetaInterface m) {\n  int t = m.getType();\n  return t == ValueMetaInterface.TYPE_NUMBER || t == ValueMetaInterface.TYPE_INTEGER || t == ValueMetaInterface.TYPE_BIGNUMBER;\n}","tryCatchPattern":"try {\n  rounded = ValueDataUtil.round(metaA, dataA);\n} catch (KettleValueException e) {\n  logError(\"round() on non-numeric field: \" + e.getMessage());\n  rounded = null;\n}","preventionTips":["Convert file-sourced strings to numbers before any rounding step.","Check field types in a Select Values metadata tab before every Calculator usage.","Use row error handling so one bad row doesn't kill the transformation."],"tags":["kettle","pdi","rounding","numeric-types"],"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"}