{"record":{"id":"305697627b05ebcd","repo":"pentaho/pentaho-kettle","slug":"could-not-apply-the-given-format-on-the-number-e-getmessage-305697","errorCode":null,"errorMessage":"Could not apply the given format on the number : {e.getMessage()}","messagePattern":"Could not apply the given format on the number : (.+?)","errorType":"exception","errorClass":"JavaScriptException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1349,"sourceCode":"    String sRC = \"\";\n    switch ( ArgList.length ) {\n      case 0:\n        throw Context.reportRuntimeError( \"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) 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          DecimalFormat formatter = new DecimalFormat();\n          sRC = formatter.format( sArg1 );\n        } catch ( IllegalArgumentException e ) {\n          throw Context.reportRuntimeError( \"Could not apply the given format on the number : \" + e.getMessage() );\n        }\n        break;\n      case 2:\n        try {\n          if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n            return null;\n          } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n            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          DecimalFormat formatter = new DecimalFormat( sArg2 );\n          sRC = formatter.format( sArg1 );\n        } catch ( IllegalArgumentException e ) {\n          throw Context.reportRuntimeError( \"Could not apply the given format on the number : \" + e.getMessage() );","sourceCodeStart":1331,"sourceCodeEnd":1367,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1331-L1367","documentation":"After validating the number, the 1-argument num2str formats it with a default DecimalFormat. If DecimalFormat.format throws IllegalArgumentException, the function rethrows this error embedding the underlying exception message. It means the number formatting operation itself failed unexpectedly.","triggerScenarios":" DecimalFormat.format(double) throwing IllegalArgumentException during default-locale formatting — rare, but triggered by broken default locale configuration (Locale with invalid patterns) or a JVM-level DecimalFormat failure surfaced via the catch block.","commonSituations":"Pentaho/Kettle server JVM running with a malformed default locale (user.language/user.country settings); custom DecimalFormat provider issues; running under an unusual Java version where default pattern handling changed.","solutions":["Check the JVM's default locale settings (-Duser.language, -Duser.country) and ensure they form a valid locale.","Use the 2-argument form with an explicit valid format pattern to bypass default-locale formatting.","Inspect e.getMessage() in the error for the concrete DecimalFormat cause and fix that configuration."],"exampleFix":"// before (relies on broken default locale)\nvar s = num2str(value);\n\n// after (explicit pattern)\nvar s = num2str(value, \"#.##\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// In JS step you cannot catch Rhino runtime errors from added functions reliably;\n// fix the environment instead: verify JVM locale flags are valid,\n// or bypass the default formatter by passing an explicit pattern.\nvar s = num2str(value, \"#.##\");","preventionTips":["Pin valid -Duser.language/-Duser.country on Kettle server JVMs.","Prefer explicit DecimalFormat patterns over relying on the default locale.","Log the embedded e.getMessage() when this occurs to identify the environment cause."],"tags":["java","locale","number-format","decimalformat"],"backgroundTag":"invalid-argument-format","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"}