{"record":{"id":"921369202d6f5944","repo":"pentaho/pentaho-kettle","slug":"function-trunc-only-works-on-numbers-and-dates","errorCode":null,"errorMessage":"Function TRUNC only works on numbers and dates","messagePattern":"Function TRUNC only works on numbers and dates","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":3470,"sourceCode":"      return this;\n    }\n\n    if ( isBigNumber() ) {\n      getBigNumber().setScale( 0, BigDecimal.ROUND_FLOOR );\n    } else if ( isNumber() ) {\n      setValue( Math.floor( getNumber() ) );\n    } else if ( isDate() ) {\n      Calendar cal = Calendar.getInstance();\n      cal.setTime( getDate() );\n\n      cal.set( Calendar.MILLISECOND, 0 );\n      cal.set( Calendar.SECOND, 0 );\n      cal.set( Calendar.MINUTE, 0 );\n      cal.set( Calendar.HOUR_OF_DAY, 0 );\n\n      setValue( cal.getTime() );\n    } else {\n      throw new KettleValueException( \"Function TRUNC only works on numbers and dates\" );\n    }\n\n    return this;\n  }\n\n  // implement the TRUNC function, arguments in args[]\n  public Value trunc( double level ) throws KettleValueException {\n    return trunc( (int) level );\n  }\n\n  @SuppressWarnings( { \"fallthrough\", \"squid:S128\" } )\n  public Value trunc( int level ) throws KettleValueException {\n    if ( isNull() ) {\n      return this; // don't do anything, leave it at NULL!\n    }\n\n    if ( isInteger() ) {\n      return this; // nothing to do.","sourceCodeStart":3452,"sourceCodeEnd":3488,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L3452-L3488","documentation":"Type dispatch guard in the no-argument legacy Value trunc() overload: the value is neither BigNumber, Number nor Date, so there is no truncation semantic to apply and the switch falls through to this sentinel error. The input at fault is the current Value of an unsupported type (e.g. String or Boolean).","triggerScenarios":"Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3470 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the field passed to TRUNC is a Number, BigNumber or Date","Convert the value to a numeric or date type before truncating"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}