Skip to content

Latest commit

 

History

History
128 lines (78 loc) · 6.79 KB

File metadata and controls

128 lines (78 loc) · 6.79 KB

WordsToDecimalNumberExtension Class

Converts English decimal number words into System.Decimal values.

public static class WordsToDecimalNumberExtension

Inheritance System.Object → WordsToDecimalNumberExtension

Methods

WordsToDecimalNumberExtension.ToDecimalNumber(this string, CultureInfo) Method

Converts English decimal number words containing one point 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 English 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 an English culture.

Remarks

The integer part uses the existing English words-to-number grammar. The fractional part requires one to 28 digit words (zero through nine); conjunctions are not accepted after point. A leading minus or negative applies to the complete value. The integer part may be omitted, as in point five. A decimal marker and at least one fractional digit word are required.

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

Attempts to convert English 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 English 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 English 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 English 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.