Humanizr/Humanizer · error · NotSupportedException

Decimal word parsing is not supported for the requested cult

Error message

Decimal word parsing is not supported for the requested culture.

What it means

UnsupportedWordsToDecimalNumberConverter.Convert throws NotSupportedException at line 18 to signal that the resolved culture has no decimal word parser. The decimal registry returns this stub for cultures without authored decimal words (unlike the integer registry, it does not fall back to English). Notably TryConvert returns false rather than throwing, so callers can avoid the exception entirely.

Source

Thrown at src/Humanizer/Localisation/WordsToNumber/UnsupportedWordsToDecimalNumberConverter.cs:18

namespace Humanizer;

/// <summary>
/// Fallback converter used when a locale does not support decimal word parsing.
/// </summary>
internal sealed class UnsupportedWordsToDecimalNumberConverter : IWordsToDecimalNumberConverter
{
    internal static UnsupportedWordsToDecimalNumberConverter Instance { get; } = new();

    UnsupportedWordsToDecimalNumberConverter()
    {
    }

    /// <inheritdoc />
    public decimal Convert(string words)
    {
        ArgumentNullException.ThrowIfNull(words);
        throw new NotSupportedException("Decimal word parsing is not supported for the requested culture.");
    }

    /// <inheritdoc />
    public bool TryConvert(string words, out decimal parsedValue)
    {
        parsedValue = default;
        return false;
    }

    /// <inheritdoc />
    public bool TryConvert(string words, out decimal parsedValue, out string? unrecognizedNumber)
    {
        parsedValue = default;
        unrecognizedNumber = words ?? string.Empty;
        return false;
    }
}

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Use TryToDecimalNumber(words, out var d, culture) which returns false without throwing.
  2. Verify the culture has decimal-word support before calling Convert; fall back to a supported culture (e.g. en) if needed.
  3. Catch NotSupportedException only as a last resort if you must call Convert.

Example fix

// before
var d = words.ToDecimalNumber(CultureInfo.GetCultureInfo("xx"));  // throws NotSupportedException
// after
if (words.TryToDecimalNumber(out var d, CultureInfo.GetCultureInfo("xx")))
    Use(d);
else
    UseFallback();
Defensive patterns

Strategy: validation

Validate before calling

// Try* returns false without throwing for unsupported cultures.
if (!words.TryToDecimalNumber(out var d, culture))
{
    // culture lacks decimal-word support; fall back or skip
    return Result.Unsupported();
}
return Result.Ok(d);

Try / catch

try { var d = words.ToDecimalNumber(culture); }
catch (NotSupportedException ex) when (ex.Message.Contains("not supported for the requested culture"))
    { /* no decimal parser for this culture */ }

Prevention

When it happens

Trigger: Calling ToDecimalNumber(words, culture) for a culture that lacks decimal-word support. The stub is returned by GetWordsToDecimalNumberConverter; Convert throws, but TryConvert returns false.

Common situations: Requesting decimal parsing for a locale that only authored integer words; assuming decimal words exist for every culture; using a neutral/unsupported culture code.

Related errors


AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13). Data as JSON: /api/errors/c771d651cef3755c. Report an issue: GitHub.