pentaho/pentaho-kettle · error · RuntimeException

Could not apply the given format on the number : " +…

Error message

Could not apply the given format on the number : " + e.getMessage()

What it means

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.

Solutions

  1. Inspect the wrapped e.getMessage() to see the underlying DecimalFormat error.
  2. Use the two-argument num2str(number, pattern) form with an explicit valid pattern.
  3. Verify the JVM's default locale / DecimalFormat configuration is valid.
  4. Catch the exception and fall back to a plain String.valueOf(number).

Example fix

// before
var s = num2str(value);
// after
var s;
try { s = num2str(value); } catch(e) { s = String(value); }
Defensive patterns

Strategy: try-catch

Validate before calling

if (typeof value !== "number" || isNaN(value)) { value = 0; }

Type guard

function isNum(v) { return typeof v === "number" && !isNaN(v); }

Try / catch

try { return num2str(value); } catch (e) { return java.lang.String.valueOf(value); }

Prevention

When it happens

Trigger: 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.

Common situations: Non-default system locale with custom format settings; JVM runtime configuration issues; rarely hit since format() of a valid double seldom throws.

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


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/7d0b7d6be8353a5d. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:1315

    String sRC = "";
    switch ( ArgList.length ) {
      case 0:
        throw new RuntimeException( "The function call num2str requires at least 1 argument." );
      case 1:
        try {
          if ( isNull( ArgList[0] ) ) {
            return null;
          } else if ( isUndefined( ArgList[0] ) ) {
            return (String) undefinedValue;
          }
          double sArg1 = (Double) ArgList[0];
          if ( Double.isNaN( sArg1 ) ) {
            throw new RuntimeException( "The first Argument must be a Number." );
          }
          DecimalFormat formatter = new DecimalFormat();
          sRC = formatter.format( sArg1 );
        } catch ( IllegalArgumentException e ) {
          throw new RuntimeException( "Could not apply the given format on the number : " + e.getMessage() );
        }
        break;
      case 2:
        try {
          if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
            return null;
          } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
            return (String) undefinedValue;
          }
          double sArg1 = (Double) ArgList[0];
          if ( Double.isNaN( sArg1 ) ) {
            throw new RuntimeException( "The first Argument must be a Number." );
          }
          String sArg2 = (String) ArgList[1];
          DecimalFormat formatter = new DecimalFormat( sArg2 );
          sRC = formatter.format( sArg1 );
        } catch ( IllegalArgumentException e ) {
          throw new RuntimeException( "Could not apply the given format on the number : " + e.getMessage() );

View on GitHub (pinned to f3058517a1)