TheAlgorithms/Java · error · WordsToNumberException

MISSING_DECIMAL_NUMBERS

MISSING_DECIMAL_NUMBERS

Error message

Invalid Input. Decimal part is missing numbers.

What it means

Thrown in convertDecimalPart when the word 'point' is not followed by any number words — the decimal StringBuilder remains at length 1 (just '.'). This means 'point' was the last token in the input with nothing after it.

Source

Thrown at src/main/java/com/thealgorithms/conversions/WordsToNumber.java:294

                    int numberDigitCount = number.toString().length();
                    return chunkDigitCount > numberDigitCount;
                }

                private static String convertDecimalPart(ArrayDeque<String> wordDeque) {
                    StringBuilder decimalPart = new StringBuilder(".");

                    while (!wordDeque.isEmpty()) {
                        String word = wordDeque.poll();
                        Integer number = NumberWord.getValue(word);
                        if (number == null) {
                            throw new WordsToNumberException(WordsToNumberException.ErrorType.UNEXPECTED_WORD_AFTER_POINT, word);
                        }
                        decimalPart.append(number);
                    }

                    boolean missingNumbers = decimalPart.length() == 1;
                    if (missingNumbers) {
                        throw new WordsToNumberException(WordsToNumberException.ErrorType.MISSING_DECIMAL_NUMBERS, "");
                    }
                    return decimalPart.toString();
                }

                private static BigDecimal combineChunks(List<BigDecimal> chunks) {
                    BigDecimal completeNumber = BigDecimal.ZERO;
                    for (BigDecimal chunk : chunks) {
                        completeNumber = completeNumber.add(chunk);
                    }
                    return completeNumber;
                }
        }

        class WordsToNumberException extends RuntimeException {

                @Serial private static final long serialVersionUID = 1L;

                enum ErrorType {

View on GitHub (pinned to fdfb9a395b)

Solutions

  1. Ensure 'point' is always followed by at least one single-digit number word.
  2. Trim trailing 'point' from input if it is spurious.
  3. Validate that 'point' is not the final token before calling convert.

Example fix

// before
WordsToNumber.convert('one point');
// after
WordsToNumber.convert('one point five'); // 1.5
Defensive patterns

Strategy: validation

Validate before calling

static String ensureDecimalFollowed(String s) {
    String[] words = s.trim().toLowerCase(Locale.ROOT).split("[ ,-]+");
    if (words.length > 0 && "point".equals(words[words.length - 1])) {
        throw new IllegalArgumentException("'point' must be followed by digit words");
    }
    return s;
}

Try / catch

try { WordsToNumber.convert(input); } catch (WordsToNumberException e) {
    if (e.errorType == ErrorType.MISSING_DECIMAL_NUMBERS) throw new ApiException(400, "'point' must be followed by at least one digit word");
    throw e;
}

Prevention

When it happens

Trigger: convert('one point'), convert('five point '), convert('negative ten point'). Any input ending with 'point' and no subsequent digit words.

Common situations: Truncated input; copy-paste that drops trailing words; voice input cutoff; programmatic phrase construction that omits the decimal digits.

Related errors


AI-assisted analysis of TheAlgorithms/Java@fdfb9a395b (2026-08-13). Data as JSON: /api/errors/e3569201283e3172. Report an issue: GitHub.