Skip to main content
Version: 4.0 (next)

Humanizer.IWordsToNumberConverter

IWordsToNumberConverter Interface

Converts localized number words into numeric values.

public interface IWordsToNumberConverter

Remarks

Implementations expect a meaningful localized number phrase. They may throw System.ArgumentException for null, empty, or whitespace input, and fallback implementations for unsupported locales may throw System.NotSupportedException instead of returning a parse failure.

Methods

IWordsToNumberConverter.Convert(string) Method

Converts words into a numeric value.

long Convert(string words);

Parameters

words System.String

The localized number phrase to convert.

Returns

System.Int64
The parsed numeric value.

Exceptions

System.ArgumentException
If words is null, empty, whitespace, or cannot be parsed by the current implementation.

System.NotSupportedException
If the current implementation does not support words-to-number conversion for its locale.

IWordsToNumberConverter.TryConvert(string, long) Method

Attempts to convert words into a numeric value.

bool TryConvert(string words, out long parsedValue);

Parameters

words System.String

The localized number phrase to convert.

parsedValue System.Int64

When this method returns, contains the parsed numeric value. The value is meaningful only when the method returns true.

Returns

System.Boolean
true if the phrase was parsed successfully; otherwise, false.

Exceptions

System.ArgumentException
If words is null, empty, or whitespace.

System.NotSupportedException
If the current implementation does not support words-to-number conversion for its locale.

IWordsToNumberConverter.TryConvert(string, long, string) Method

Attempts to convert words into a numeric value and reports the first token-like fragment that could not be interpreted when parsing fails.

bool TryConvert(string words, out long parsedValue, out string? unrecognizedNumber);

Parameters

words System.String

The localized number phrase to convert.

parsedValue System.Int64

When this method returns, contains the parsed numeric value. The value is meaningful only when the method returns true.

unrecognizedNumber System.String

When parsing fails, the best-effort token or fragment that remained unrecognized.

Returns

System.Boolean
true if the value was parsed successfully; otherwise, false.

Exceptions

System.ArgumentException
If words is null, empty, or whitespace.

System.NotSupportedException
If the current implementation does not support words-to-number conversion for its locale.