{"record":{"id":"7d0b7d6be8353a5d","repo":"pentaho/pentaho-kettle","slug":"could-not-apply-the-given-format-on-the-number-e-getmessage","errorCode":null,"errorMessage":"Could not apply the given format on the number : \" + e.getMessage()","messagePattern":"Could not apply the given format on the number : \" \\+ e\\.getMessage\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1315,"sourceCode":"    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:\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) 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          String sArg2 = (String) ArgList[1];\n          DecimalFormat formatter = new DecimalFormat( sArg2 );\n          sRC = formatter.format( sArg1 );\n        } catch ( IllegalArgumentException e ) {\n          throw new RuntimeException( \"Could not apply the given format on the number : \" + e.getMessage() );","sourceCodeStart":1297,"sourceCodeEnd":1333,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1297-L1333","documentation":"In num2str's one-argument case, any IllegalArgumentException from DecimalFormat.format() (invalid implicit format / locale problems) is rethrown as this RuntimeException wrapping the original message.","triggerScenarios":"Calling num2str(number) when the JVM's default DecimalFormat or locale rejects the formatting operation, e.g. a malformed default format pattern set via system settings.","commonSituations":"Non-default system locale with custom format settings; JVM runtime configuration issues; rarely hit since format() of a valid double seldom throws.","solutions":["Inspect the wrapped e.getMessage() to see the underlying DecimalFormat error.","Use the two-argument num2str(number, pattern) form with an explicit valid pattern.","Verify the JVM's default locale / DecimalFormat configuration is valid.","Catch the exception and fall back to a plain String.valueOf(number)."],"exampleFix":"// before\nvar s = num2str(value);\n// after\nvar s;\ntry { s = num2str(value); } catch(e) { s = String(value); }","handlingStrategy":"try-catch","validationCode":"if (typeof value !== \"number\" || isNaN(value)) { value = 0; }","typeGuard":"function isNum(v) { return typeof v === \"number\" && !isNaN(v); }","tryCatchPattern":"try { return num2str(value); } catch (e) { return java.lang.String.valueOf(value); }","preventionTips":["Prefer explicit 2-arg num2str over relying on default locale formats","Keep JVM locale settings consistent across environments","Log the wrapped e.getMessage() to diagnose DecimalFormat issues"],"tags":["decimalformat","number-formatting","wrapped-exception"],"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"}