{"record":{"id":"b3d25f9dab5920a9","repo":"pentaho/pentaho-kettle","slug":"the-function-call-trunc-requires-1-argument-a-number-b3d25f","errorCode":null,"errorMessage":"The function call trunc requires 1 argument, a number.","messagePattern":"The function call trunc requires 1 argument, a number\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2490,"sourceCode":"  public static Object trunc( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      // 1 argument: normal truncation of numbers\n      //\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return Context.getUndefinedValue();\n        }\n\n        // This is the truncation of a number...\n        //\n        Double dArg1 = (Double) Context.jsToJava( ArgList[0], Double.class );\n        return Double.valueOf( Math.floor( dArg1 ) );\n\n      } else {\n        throw Context.reportRuntimeError( \"The function call trunc requires 1 argument, a number.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n\n  @SuppressWarnings( \"fallthrough\" )\n  public static Object truncDate( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) {\n      // 2 arguments: truncation of dates to a certain precision\n      //\n    if ( ArgList.length == 2 ) {\n      if ( isNull( ArgList[0] ) ) {\n        return null;\n      } else if ( isUndefined( ArgList[0] ) ) {\n        return Context.getUndefinedValue();\n      }\n\n      // This is the truncation of a date...","sourceCodeStart":2472,"sourceCodeEnd":2508,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2472-L2508","documentation":"trunc() truncates a number to its integer part via Math.floor. This error is thrown when the JS call does not supply exactly 1 argument (the else branch), meaning the function's signature contract was violated. Note it truncates toward negative infinity, which surprises some users, but this specific message is purely an argument-count failure.","triggerScenarios":"trunc() with no arguments, trunc(x, y) with extra arguments, or any call where ArgList length differs from 1 in a Modified Java Script Value step.","commonSituations":"Porting Oracle/Excel TRUNC(date|number, fmt) habits into Kettle JS and passing a second precision argument; calling trunc on a date intending truncDate instead.","solutions":["Call trunc with exactly one numeric argument: trunc(value).","Use truncDate(date, level) instead when the argument is a Date.","Convert strings to numbers first: trunc(parseFloat(str)) or trunc(new Number(str).doubleValue()).","Check upstream field types; a field typed as String may still pass but a wrong arg count will not."],"exampleFix":"// before\nvar t = trunc(amount, 2); // wrong: extra precision arg\n// after\nvar t = trunc(amount); // floors to integer; use your own scaling for 2 decimals","handlingStrategy":"validation","validationCode":"function safeTrunc(v) { if (v == null || isNaN(parseFloat(v))) return null; return trunc(parseFloat(v)); }","typeGuard":"function isNumber(v) { return typeof v === 'number' && !isNaN(v); }","tryCatchPattern":"try { t = trunc(x); } catch (e) { Logger.LogError('trunc failed: ' + e.message); t = null; }","preventionTips":["Call trunc with exactly one numeric argument","Use truncDate for Date inputs","Do not port SQL TRUNC(date,fmt) semantics to this function"],"tags":["javascript","scripting","argument-count","rhino"],"backgroundTag":"missing-required-argument","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"}