{"record":{"id":"4d07e67481576545","repo":"pentaho/pentaho-kettle","slug":"division-can-only-be-done-with-numeric-data","errorCode":null,"errorMessage":"Division can only be done with numeric data!","messagePattern":"Division can only be done with numeric data!","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":2282,"sourceCode":"\n  public Value divide( Value v ) throws KettleValueException {\n    if ( isNull() || v.isNull() ) {\n      setNull();\n    } else {\n      switch ( getType() ) {\n        case VALUE_TYPE_BIGNUMBER:\n          setValue( getBigNumber().divide( v.getBigNumber(), BigDecimal.ROUND_HALF_UP ) );\n          break;\n        case VALUE_TYPE_NUMBER:\n          setValue( getNumber() / v.getNumber() );\n          break;\n        case VALUE_TYPE_INTEGER:\n          setValue( getInteger() / v.getInteger() );\n          break;\n        case VALUE_TYPE_BOOLEAN:\n        case VALUE_TYPE_STRING:\n        default:\n          throw new KettleValueException( \"Division can only be done with numeric data!\" );\n      }\n    }\n    return this;\n  }\n\n  public Value multiply( BigDecimal v ) throws KettleValueException {\n    return multiply( new Value( \"tmp\", v ) );\n  }\n\n  public Value multiply( double v ) throws KettleValueException {\n    return multiply( new Value( \"tmp\", v ) );\n  }\n\n  public Value multiply( long v ) throws KettleValueException {\n    return multiply( new Value( \"tmp\", v ) );\n  }\n\n  public Value multiply( int v ) throws KettleValueException {","sourceCodeStart":2264,"sourceCodeEnd":2300,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L2264-L2300","documentation":"This KettleValueException is thrown by Value.divide() when division is attempted with a non-numeric operand type (Boolean, String, or unhandled default). The compatibility Value class supports division only for Number, Integer, and BigNumber types and rejects all others explicitly to avoid silent misbehavior.","triggerScenarios":"value.divide(other) where either operand is VALUE_TYPE_STRING, VALUE_TYPE_BOOLEAN, or another unsupported type — commonly a String field from parsed text used directly as a divisor, or a zero/invalid divisor path guarded only by type checks.","commonSituations":"CSV/Excel inputs inferred as String; calculator step receiving text fields; upstream steps changed a field's metadata type; forgot type conversion before division in a scripted mapping.","solutions":["Convert both operands to numeric types before dividing (convertString( VALUE_TYPE_NUMBER ) or new Value with a numeric value).","Add a Select Values step to force the field type to Number/Integer upstream of the division.","Check the divisor for zero before dividing to also avoid infinite/NaN results.","Validate ValueMetaInterface types in the step before performing the operation.","Catch KettleValueException and report the offending field name and type to the user."],"exampleFix":"// before\nValue ratio = countValue.divide( strTotal ); // throws: strTotal is STRING\n// after\nstrTotal.convertString( Value.VALUE_TYPE_BIGNUMBER );\nValue ratio = countValue.divide( strTotal );","handlingStrategy":"type-guard","validationCode":"// before division\nif ( !( num.isNumber() || num.isInteger() || num.isBigNumber() ) ) num.convertString( Value.VALUE_TYPE_NUMBER );\nif ( den.isBigNumber() && den.getBigNumber().signum() == 0 ) throw new ArithmeticException( \"Divide by zero\" );","typeGuard":"boolean isDivisible( Value v ) {\n  return v != null && ( v.isNumber() || v.isInteger() || v.isBigNumber() );\n}","tryCatchPattern":"try {\n  Value ratio = a.divide( b );\n} catch ( KettleValueException e ) {\n  throw new IllegalStateException( \"Non-numeric operand for divide(): check field types\", e );\n}","preventionTips":["Coerce divisor/dividend field types to numeric upstream of division.","Zero-check divisors before dividing.","Validate metadata types in the step before operating.","Convert CSV/text numerics explicitly at ingestion.","Test transformations with representative field-type metadata."],"tags":["arithmetic","type-mismatch","division","value-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"}