pentaho/pentaho-kettle · error · RhinoRuntimeError
Could not convert the given String :
Error message
Could not convert the given String :
What it means
str2num parses its string argument with a default DecimalFormat and calls parse(...).doubleValue(). If parsing fails (non-numeric text, unexpected characters), the caught Exception is rethrown as this error with the exception message appended. The string could not be converted to a number under the current default locale's DecimalFormat rules.
Solutions
- Clean the string before parsing: trim and strip currency symbols/units, then retry str2num.
- Match separators to the JVM's default locale, or pre-normalize "1.234,56"-style strings manually.
- Use the 2-argument form with an explicit DecimalFormat pattern matching the input format.
- Check the server's -Duser.language/-Duser.country settings if parsing works locally but not on the server.
- Decide a fallback for unparseable values (default 0 or NaN) with a isNaN check after a guarded call.
Example fix
// before
var n = str2num(amountText); // "€1.234,56 " under en locale fails
// after
var cleaned = trim(amountText).replace("€", "").replace("\.", "").replace(",", ".");
var n = str2num(cleaned); Defensive patterns
Strategy: validation
Validate before calling
function isParseableNumber(s) {
if (typeof s !== 'string') return false;
var t = s.replace(/^\s+/, '').replace(/[\s\u00a4]/g, '');
return /^-?\d+([.,]\d+)?$/.test(t);
}
if (isParseableNumber(amountText)) { var n = str2num(amountText); } Type guard
function isNumericString(v) { return typeof v === 'string' && !isNaN(Number(v.replace(',', '.'))); } Prevention
- Trim and strip currency symbols/units before parsing.
- Align decimal/thousands separators with the JVM default locale or pre-normalize.
- Confirm server and dev machines share the same locale settings.
- Handle 'N/A'/dash placeholders upstream before conversion.
When it happens
Trigger: str2num(s) where s contains non-numeric text, a thousands separator inconsistent with the default locale (e.g. "1,234.56" under a German locale), currency symbols, whitespace beyond leading spaces (Const.ltrim only trims the left), or empty/trailing garbage after a number when DecimalFormat is strict.
Common situations: CSV/Excel imports where numbers carry currency symbols or locale-mismatched separators; fields that should be numeric but contain "N/A" or "-"; Kettle server JVM default locale differing from the developer's machine so the same string parses locally but fails on the server; trailing spaces or units ("12 kg").
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- e.toString()
- The first Argument must be a Number.
- The function call str2num requires at least 1 argument.
- AnalyticQueryMeta.Exception.UnableToLoadStepInfoFromXML
- Caught a number format exception converting minimum length…
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/c2cdd34d76f5b201.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:1420
double dRC = 0.00;
switch ( ArgList.length ) {
case 0:
throw Context.reportRuntimeError( "The function call str2num requires at least 1 argument." );
case 1:
try {
if ( isNull( ArgList[0] ) ) {
return new Double( Double.NaN );
} else if ( isUndefined( ArgList[0] ) ) {
return Context.getUndefinedValue();
}
if ( ArgList[0].equals( null ) ) {
return null;
}
String sArg1 = Context.toString( ArgList[0] );
DecimalFormat formatter = new DecimalFormat();
dRC = ( formatter.parse( Const.ltrim( sArg1 ) ) ).doubleValue();
} catch ( Exception e ) {
throw Context.reportRuntimeError( "Could not convert the given String : " + e.getMessage() );
}
break;
case 2:
try {
if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
return new Double( Double.NaN );
} else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
return Context.getUndefinedValue();
}
String sArg1 = Context.toString( ArgList[0] );
String sArg2 = Context.toString( ArgList[1] );
if ( sArg1.equals( "null" ) || sArg2.equals( "null" ) ) {
return null;
}
DecimalFormat formatter = new DecimalFormat( sArg2 );
dRC = ( formatter.parse( sArg1 ) ).doubleValue();
return new Double( dRC );
} catch ( Exception e ) {View on GitHub (pinned to f3058517a1)