Skip to main content
Version: 4.0 (next)

Humanizer.WordsToDecimalNumberExtension

WordsToDecimalNumberExtension Class​

Converts localized decimal number words into System.Decimal values.

public static class WordsToDecimalNumberExtension

Inheritance System.Object → WordsToDecimalNumberExtension

Methods​

WordsToDecimalNumberExtension.ToDecimalNumber(this string, CultureInfo) Method​

Converts localized decimal number words containing one locale-specific decimal marker to a decimal value.

public static decimal ToDecimalNumber(this string words, System.Globalization.CultureInfo culture);
Parameters​

words System.String

The decimal number words to convert.

culture System.Globalization.CultureInfo

The culture to use for parsing.

Returns​

System.Decimal
The parsed decimal value, including its authored fractional scale.

Exceptions​

System.ArgumentNullException
If words is null.

System.FormatException
If the phrase is malformed or outside the supported System.Decimal range.

System.NotSupportedException
If culture is not supported.

Remarks​

The integer part uses the selected culture's words-to-number grammar. The fractional part requires one to 28 localized digit words. A supported negative affix applies to the complete value. The integer part may be omitted. A decimal marker and at least one fractional digit word are required. Markers and digit words follow the selected grammar's token boundaries. English scale phrases may exceed the System.Int64 range when the result fits in a System.Decimal; other cultures use the range supported by their words-to-number grammar.

WordsToDecimalNumberExtension.TryToDecimalNumber(this string, decimal, CultureInfo) Method​

Attempts to convert localized decimal number words without throwing for malformed input, unsupported cultures, or values outside the supported System.Decimal range.

public static bool TryToDecimalNumber(this string words, out decimal parsedNumber, System.Globalization.CultureInfo culture);
Parameters​

words System.String

The decimal number words to convert.

parsedNumber System.Decimal

When this method returns, contains the parsed value if successful; otherwise, zero.

culture System.Globalization.CultureInfo

The culture to use for parsing.

Returns​

System.Boolean
true if conversion succeeded; otherwise, false.

WordsToDecimalNumberExtension.TryToDecimalNumber(this string, decimal, CultureInfo, string) Method​

Attempts to convert localized decimal number words and reports the first unrecognized token.

public static bool TryToDecimalNumber(this string words, out decimal parsedNumber, System.Globalization.CultureInfo culture, out string? unrecognizedWord);
Parameters​

words System.String

The decimal number words to convert.

parsedNumber System.Decimal

When this method returns, contains the parsed value if successful; otherwise, zero.

culture System.Globalization.CultureInfo

The culture to use for parsing.

unrecognizedWord System.String

When conversion fails, the best-effort unrecognized token or phrase.

Returns​

System.Boolean
true if conversion succeeded; otherwise, false.