{"record":{"id":"48c2d93d6cfb3014","repo":"pentaho/pentaho-kettle","slug":"couldn-t-convert-number-to-string","errorCode":null,"errorMessage":"Couldn't convert Number to String ","messagePattern":"Couldn't convert Number to String ","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":3079,"sourceCode":"        if ( currencySymbol != null && currencySymbol.length() > 0 ) {\n          dfs.setCurrencySymbol( currencySymbol );\n        }\n        if ( groupingSymbol != null && groupingSymbol.length() > 0 ) {\n          dfs.setGroupingSeparator( groupingSymbol.charAt( 0 ) );\n        }\n        if ( decimalSymbol != null && decimalSymbol.length() > 0 ) {\n          dfs.setDecimalSeparator( decimalSymbol.charAt( 0 ) );\n        }\n        df.setDecimalFormatSymbols( dfs ); // in case of 4, 3 or 2\n        if ( format != null && format.length() > 0 ) {\n          df.applyPattern( format );\n        }\n        try {\n          setValue( nf.format( getNumber() ) );\n        } catch ( Exception e ) {\n          setType( VALUE_TYPE_STRING );\n          setNull();\n          throw new KettleValueException( \"Couldn't convert Number to String \" + e.toString() );\n        }\n      } else {\n        throw new KettleValueException( \"Function NUM2STR only works on Numbers and Integers\" );\n      }\n    }\n    return this;\n  }\n\n  // date: TO_CHAR( <date> , 'yyyy/mm/dd HH:mm:ss'\n  public Value dat2str() throws KettleValueException {\n    return dat2str( null, null );\n  }\n\n  public Value dat2str( String arg0 ) throws KettleValueException {\n    return dat2str( arg0, null );\n  }\n\n  public Value dat2str( String arg0, String arg1 ) throws KettleValueException {","sourceCodeStart":3061,"sourceCodeEnd":3097,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L3061-L3097","documentation":"Thrown by Value.to_char() for numeric values when the DecimalFormat (nf.format(getNumber())) fails. On failure the value is set to a null String and KettleValueException is rethrown with the underlying exception text appended. This is the NUM2STR conversion path for Number/Integer values.","triggerScenarios":"Calling value.to_char() on a numeric Value with a format pattern that DecimalFormat rejects or cannot apply (e.g. 'L' currency symbol with no locale support, illegal pattern characters), or a number that the chosen format cannot render (NaN/Infinity with certain patterns).","commonSituations":"User-supplied format masks with typos (e.g. '##0.00x'); locale-dependent currency symbols unavailable at runtime; migrating format strings from Oracle TO_CHAR to Java DecimalFormat syntax.","solutions":["Validate the decimal format pattern before use — it must be valid Java DecimalFormat syntax, not Oracle TO_CHAR syntax.","Simplify the pattern (e.g. '#,##0.00') to test whether the mask is the problem.","Check the appended e.toString() in the message to identify the exact format failure.","Handle null result: the value is set to null String before the throw, so downstream code must expect a null on failure."],"exampleFix":"// before\nvalue.to_char(\"999,999.00\"); // Oracle-style pattern, DecimalFormat throws\n// after\nvalue.to_char(\"#,##0.00\"); // valid DecimalFormat pattern","handlingStrategy":"try-catch","validationCode":"try { new java.text.DecimalFormat(pattern); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(\"Invalid numeric format pattern: \" + pattern); }","typeGuard":null,"tryCatchPattern":"try { result = value.to_char(pattern); } catch (KettleValueException e) { log.error(\"NUM2STR format failed: \" + e.getMessage()); result = String.valueOf(value.getNumber()); }","preventionTips":["Use Java DecimalFormat syntax, not Oracle TO_CHAR masks","Test format patterns against representative values","Read the appended e.toString() in the message to diagnose the format failure","Be aware the value is set to null String before the throw"],"tags":["kettle","number-formatting","decimals"],"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"}