{"record":{"id":"c1e3a0edd823f8f9","repo":"pentaho/pentaho-kettle","slug":"the-function-call-num2str-requires-1-2-or-3-arguments-c1e3a0","errorCode":null,"errorMessage":"The function call num2str requires 1, 2, or 3 arguments.","messagePattern":"The function call num2str requires 1, 2, or 3 arguments\\.","errorType":"exception","errorClass":"RhinoRuntimeError","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1393,"sourceCode":"            return (String) Context.getUndefinedValue();\n          }\n          double sArg1 = Context.toNumber( ArgList[0] );\n          if ( Double.isNaN( sArg1 ) ) {\n            throw Context.reportRuntimeError( \"The first Argument must be a Number.\" );\n          }\n          String sArg2 = Context.toString( ArgList[1] );\n          String sArg3 = Context.toString( ArgList[2] );\n          if ( sArg3.length() == 2 ) {\n            DecimalFormatSymbols dfs = new DecimalFormatSymbols( EnvUtil.createLocale( sArg3.toLowerCase() ) );\n            DecimalFormat formatter = new DecimalFormat( sArg2, dfs );\n            sRC = formatter.format( sArg1 );\n          }\n        } catch ( Exception e ) {\n          throw Context.reportRuntimeError( e.toString() );\n        }\n        break;\n      default:\n        throw Context.reportRuntimeError( \"The function call num2str requires 1, 2, or 3 arguments.\" );\n    }\n\n    return sRC;\n  }\n\n  // Converts the given String to a JScript Numeric\n  public static Object str2num( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    double dRC = 0.00;\n    switch ( ArgList.length ) {\n      case 0:\n        throw Context.reportRuntimeError( \"The function call str2num requires at least 1 argument.\" );\n      case 1:\n        try {\n          if ( isNull( ArgList[0] ) ) {\n            return new Double( Double.NaN );\n          } else if ( isUndefined( ArgList[0] ) ) {\n            return Context.getUndefinedValue();","sourceCodeStart":1375,"sourceCodeEnd":1411,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1375-L1411","documentation":"num2str supports exactly 1, 2, or 3 arguments. The switch's default branch throws this error when more than 3 arguments are supplied. The library enforces the documented arity of the function and refuses any other call shape.","triggerScenarios":"Calling num2str with 4+ arguments, e.g. num2str(value, pattern, lang, extra) — often from misunderstanding the API or trying to pass extra options like grouping or rounding flags that the function does not support.","commonSituations":"Porting code from other languages' number-format functions that accept more parameters (e.g. Python's format spec or C#'s ToString overloads); combining options the author guessed existed; accidental leftover arguments after refactoring.","solutions":["Remove extra arguments — keep only value, optional pattern, optional 2-letter language code.","Apply unsupported options (rounding, currency) before/after the call instead of via extra parameters.","Check the function's documentation/signature in ScriptValuesAddedFunctions for the supported overloads."],"exampleFix":"// before\nvar s = num2str(value, \"#,##0.00\", \"de\", true); // 4 args\n\n// after\nvar s = num2str(value, \"#,##0.00\", \"de\");","handlingStrategy":"validation","validationCode":"if (arguments.length >= 1 && arguments.length <= 3) { var s = num2str.apply(null, Array.prototype.slice.call(arguments)); }","typeGuard":"function hasValidNum2strArity(args) { return args.length >= 1 && args.length <= 3; }","tryCatchPattern":null,"preventionTips":["Remember the supported signatures: (value), (value, pattern), (value, pattern, lang).","Do not port extra parameters from other languages' format functions.","Implement extra options (rounding, currency) in script code around the call."],"tags":["javascript","kettle","argument-count","api-misuse"],"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"}