{"record":{"id":"79100fc85c2323f4","repo":"pentaho/pentaho-kettle","slug":"the-function-call-num2str-requires-at-least-1-argument","errorCode":null,"errorMessage":"The function call num2str requires at least 1 argument.","messagePattern":"The function call num2str requires at least 1 argument\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1300,"sourceCode":"        }\n        sRC = (String) ArgList[0];\n        sRC = sRC.toLowerCase();\n      } catch ( Exception e ) {\n        throw new RuntimeException( \"The function call lower is not valid : \" + e.getMessage() );\n      }\n    } else {\n      throw new RuntimeException( \"The function call lower requires 1 argument.\" );\n    }\n    return sRC;\n  }\n\n  // Converts the given Numeric to a JScript String\n  public static String num2str( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    String sRC = \"\";\n    switch ( ArgList.length ) {\n      case 0:\n        throw new RuntimeException( \"The function call num2str requires at least 1 argument.\" );\n      case 1:\n        try {\n          if ( isNull( ArgList[0] ) ) {\n            return null;\n          } else if ( isUndefined( ArgList[0] ) ) {\n            return (String) undefinedValue;\n          }\n          double sArg1 = (Double) ArgList[0];\n          if ( Double.isNaN( sArg1 ) ) {\n            throw new RuntimeException( \"The first Argument must be a Number.\" );\n          }\n          DecimalFormat formatter = new DecimalFormat();\n          sRC = formatter.format( sArg1 );\n        } catch ( IllegalArgumentException e ) {\n          throw new RuntimeException( \"Could not apply the given format on the number : \" + e.getMessage() );\n        }\n        break;\n      case 2:","sourceCodeStart":1282,"sourceCodeEnd":1318,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1282-L1318","documentation":"Thrown by num2str() in the PDI Script step when called with zero arguments; the function converts a numeric value to a string and requires at least the number itself (optional format and locale may follow).","triggerScenarios":"num2str() invoked with an empty argument list, typically because the field reference evaluated to nothing or the argument was deleted during editing.","commonSituations":"A field variable name typo resolving to empty in the script; an edited call that dropped the number; template scripts pasted with placeholder arguments removed.","solutions":["Pass the numeric field: num2str(myNumber).","Add a format argument if needed: num2str(myNumber, '####.00').","Check that the variable holding the number is not empty/undeclared in the script scope."],"exampleFix":"// before\nnum2str()\n// after\nnum2str(amount, '#,##0.00')","handlingStrategy":"validation","validationCode":"function safeNum2str(v, fmt) {\n  if (v === undefined || v === null) return null;\n  return fmt !== undefined ? num2str(v, fmt) : num2str(v);\n}","typeGuard":"function isNumber(v) { return typeof v === 'number' && !isNaN(v); }","tryCatchPattern":"try { return num2str(v); }\ncatch (e) { if (/requires at least 1 argument/.test(e.message)) return ''; throw e; }","preventionTips":["Always supply the numeric argument explicitly by field name.","Verify variable names in scripts so they do not resolve to empty.","Add an explicit format string for deterministic output across JVMs."],"tags":["javascript","scripting-step","argument-count","number-formatting"],"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"}