{"record":{"id":"ca3026b1a37360a3","repo":"pentaho/pentaho-kettle","slug":"tostring-couldn-t-convert-string-to-integer","errorCode":null,"errorMessage":"<toString()> : couldn't convert String to Integer","messagePattern":"<toString\\(\\)> : couldn't convert String to Integer","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java","lineNumber":1360,"sourceCode":"            + \" : couldn't convert String to number : non-numeric character found at position \"\n            + ( parsePosition.getIndex() + 1 ) + \" for value [\" + string + \"]\" );\n        }\n      }\n\n      if ( number instanceof Double && ( number.doubleValue() < Long.MIN_VALUE\n        || number.doubleValue() > Long.MAX_VALUE ) ) {\n        log.logBasic( \"Value [\" + string + \"] is out of range for Integer.\" );\n        if ( !ignoreOutOfRange ) {\n          throw new KettleValueException( toString()\n            + \" : couldn't convert String to Integer : value Out of Range [\" + string\n            + \"]. Change the destination data type or round to the nearest value possible for Integer by setting \"\n            + \"property KETTLE_IGNORE_OUT_OF_RANGE_EXCEPTION to \\\"Y\\\". \" );\n        }\n      }\n\n      return new Long( number.longValue() );\n    } catch ( Exception e ) {\n      throw new KettleValueException( toString() + \" : couldn't convert String to Integer\", e );\n    }\n  }\n\n  protected synchronized String convertBigNumberToString( BigDecimal number ) throws KettleValueException {\n    if ( number == null ) {\n      return null;\n    }\n\n    try {\n      return getDecimalFormat( bigNumberFormatting ).format( number );\n    } catch ( Exception e ) {\n      throw new KettleValueException( toString() + \" : couldn't convert BigNumber to String \", e );\n    }\n  }\n\n  protected synchronized BigDecimal convertStringToBigNumber( String string ) throws KettleValueException {\n    string = Const.trimToType( string, getTrimType() ); // see if trimming needs\n    // to be performed before","sourceCodeStart":1342,"sourceCodeEnd":1378,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java#L1342-L1378","documentation":"Generic fallback in ValueMetaBase.convertStringToInteger: any unexpected Exception while parsing/formatting the string as an integer is rethrown as a KettleValueException with this message and the original cause attached. It covers everything not caught earlier, e.g. unparseable text, null format issues, or non-numeric strings.","triggerScenarios":"convertStringToInteger(String) receives a string that NumberFormat.parse / the internal path cannot handle (e.g. '', 'abc', locale-formatted '1,234' under a mismatched locale) causing an exception inside the try block.","commonSituations":"CSV/text input columns typed as Integer containing blanks or garbage; locale mismatch (decimal comma vs point); null-ish placeholder strings like 'NULL' or '-' being converted.","solutions":["Inspect the chained cause (getCause()) to see the underlying parse problem, then fix the offending data.","Set the correct conversion mask / locale (setDecimalFormatSymbol/locale) on the ValueMeta so the string parses.","Handle empty/placeholder strings before conversion (map '', 'NULL', '-' to null via the input step's null-if settings).","Convert the field to String first, clean it (trim, strip grouping separators), then convert to Integer."],"exampleFix":"// before: '1.234,5' with default US locale fails\nValueMetaInterface vm = new ValueMetaInteger(\"qty\");\nvm.setConversionMask(\"####0\");\n// after: set the right grouping/decimal symbols or clean input\nvm.setGroupingSymbol(\".\");\nvm.setDecimalSymbol(\",\"); // now '1.234,5' parses","handlingStrategy":"validation","validationCode":"if (s == null || s.trim().isEmpty() || !s.trim().matches(\"-?\\\\d+(\\\\.0+)?\")) {\n    throw new IllegalArgumentException(\"Not an integer: \" + s);\n}","typeGuard":"static boolean isParseableInteger(String s) { try { Long.parseLong(s.trim()); return true; } catch (Exception e) { return false; } }","tryCatchPattern":"try {\n    Integer v = (Integer) valueMeta.convertData(stringMeta, raw);\n} catch (KettleValueException e) {\n    log.warn(\"Conversion failed for field \" + valueMeta.getName() + \": \" + e.getCause());\n}","preventionTips":["Always inspect getCause() to find the real parse failure","Configure locale-appropriate decimal/grouping symbols on the ValueMeta","Map empty/placeholder tokens ('', 'NULL', '-') to null at the input step"],"tags":["pdi","type-conversion","number-format","kettle"],"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"}