{"record":{"id":"217e5c0640950084","repo":"pentaho/pentaho-kettle","slug":"could-not-convert-the-given-string-e-getmessage","errorCode":null,"errorMessage":"Could not convert the given String : \" + e.getMessage()","messagePattern":"Could not convert the given String : \" \\+ e\\.getMessage\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1386,"sourceCode":"    double dRC = 0.00;\n    switch ( ArgList.length ) {\n      case 0:\n        throw new RuntimeException( \"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 undefinedValue;\n          }\n          if ( ArgList[0].equals( null ) ) {\n            return null;\n          }\n          String sArg1 = (String) ArgList[0];\n          DecimalFormat formatter = new DecimalFormat();\n          dRC = ( formatter.parse( Const.ltrim( sArg1 ) ) ).doubleValue();\n        } catch ( Exception e ) {\n          throw new RuntimeException( \"Could not convert the given String : \" + e.getMessage() );\n        }\n        break;\n      case 2:\n        try {\n          if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n            return new Double( Double.NaN );\n          } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n            return undefinedValue;\n          }\n          String sArg1 = (String) ArgList[0];\n          String sArg2 = (String) ArgList[1];\n          if ( sArg1.equals( \"null\" ) || sArg2.equals( \"null\" ) ) {\n            return null;\n          }\n          DecimalFormat formatter = new DecimalFormat( sArg2 );\n          dRC = ( formatter.parse( sArg1 ) ).doubleValue();\n          return new Double( dRC );\n        } catch ( Exception e ) {","sourceCodeStart":1368,"sourceCodeEnd":1404,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1368-L1404","documentation":"In str2num's one-argument case, the string is parsed with a default DecimalFormat after Const.ltrim; any exception (ParseException for non-numeric text, NullPointerException on null, cast issues) is wrapped in this RuntimeException.","triggerScenarios":"Calling str2num(s) where s is not parseable as a number under the default locale — e.g. \"1.234,56\" text in an en_US locale, or strings containing currency symbols or letters.","commonSituations":"Locale mismatch between data source and JVM default (comma vs dot decimal separators); leftover units/currency symbols; whitespace at the right side (only the left is trimmed); CSV fields that failed earlier cleansing.","solutions":["Verify the string matches the JVM default locale's number format (decimal separator, grouping).","Strip non-numeric characters (currency symbols, spaces, trailing text) before parsing.","Use the 2- or 3-argument str2num with an explicit pattern and locale matching the data.","Trim the right side manually since only ltrim is applied.","Catch the exception and return a fallback value (e.g. NaN or 0)."],"exampleFix":"// before\nvar n = str2num(\"1.234,56\"); // fails in en_US locale\n// after\nvar n = str2num(\"1.234,56\", \"#,##0.00\", \"de\"); // parse with matching format/locale","handlingStrategy":"try-catch","validationCode":"function parseSafe(s) { var t = (s == null) ? \"\" : String(s).replace(/[^0-9.,\\-+]/g, \"\"); return t.length > 0 ? t : null; }","typeGuard":"function isNumericString(v) { return typeof v === \"string\" && /^\\s*[+-]?[0-9.,]+\\s*$/.test(v); }","tryCatchPattern":"try { return str2num(s); } catch (e) { // locale/format mismatch\n  return Number.NaN; }","preventionTips":["Match the JVM default locale to the data's number format","Strip currency symbols and units before parsing","Remember only the LEFT side is trimmed — trim the right side yourself","Prefer explicit pattern/locale variants of str2num over the default"],"tags":["str2num","decimalformat","locale","parse-error"],"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"}