TheAlgorithms/Java · error · WordsToNumberException

UNEXPECTED_WORD_AFTER_POINT

UNEXPECTED_WORD_AFTER_POINT

Error message

Invalid Input. Unexpected Word (after Point): {word}

What it means

Thrown in convertDecimalPart (invoked after 'point') when a word following 'point' is not a recognized NumberWord. The decimal part expects a sequence of single-digit number words (zero-nine); any other word — including tens words, 'hundred', 'point', or unknown words — triggers this error.

Source

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

        return isNegative ? completeNumber.multiply(BigDecimal.valueOf(-1))
                :
                    completeNumber;
                }

                private static boolean isAdditionSafe(BigDecimal currentChunk, BigDecimal number) {
                    int chunkDigitCount = currentChunk.toString().length();
                    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;
                }

View on GitHub (pinned to fdfb9a395b)

Solutions

  1. After 'point', use only single-digit words: zero through nine, one per decimal place.
  2. Spell multi-digit decimals digit by digit: 'point two five' not 'point twenty five'.
  3. Pre-validate the post-'point' segment contains only zero-nine words.

Example fix

// before
WordsToNumber.convert('one point twenty five');
// after
WordsToNumber.convert('one point two five'); // 1.25
Defensive patterns

Strategy: validation

Validate before calling

static final Set<String> DIGITS = Set.of("zero","one","two","three","four","five","six","seven","eight","nine");
static boolean decimalPartValid(String s) {
    int p = s.toLowerCase(Locale.ROOT).indexOf("point");
    if (p < 0) return true;
    String[] after = s.substring(p).trim().split("[ ,-]+");
    for (int i = 1; i < after.length; i++) { if (!DIGITS.contains(after[i])) return false; }
    return true;
}

Try / catch

try { WordsToNumber.convert(input); } catch (WordsToNumberException e) {
    if (e.errorType == ErrorType.UNEXPECTED_WORD_AFTER_POINT) throw new ApiException(400, "After 'point', only single-digit words (zero-nine) are allowed");
    throw e;
}

Prevention

When it happens

Trigger: convert('one point five two') works; convert('one point twenty') fails (twenty is not single-digit); convert('one point hundred') fails; convert('one point five point') fails.

Common situations: Users trying to spell decimals with multi-digit words ('point twenty-five' instead of 'point two five'); unsupported decimal word forms; LLM output mixing scales after 'point'.

Related errors


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