Converts localized number words back into numeric values.
Parsing is culture-aware, honors locale inheritance, and supports the same natural high-range
forms that the locale authoring data exposes through number.words and
number.parse.
public static class WordsToNumberExtensionInheritance System.Object → WordsToNumberExtension
Converts a spelled-out number string to its numeric representation.
public static long ToNumber(this string words, System.Globalization.CultureInfo culture);words System.String
The spelled-out number. Must not be null.
culture System.Globalization.CultureInfo
The culture to use for parsing.
System.Int64
The numeric value represented by words.
System.FormatException
If the input contains unrecognized words or cannot be parsed as a number.
System.ArgumentNullException
If words is null.
This method now returns System.Int64 to support locale-authored high-range number parsing beyond System.Int32.MaxValue. Existing code that depended on an System.Int32 result should either switch the receiving type to System.Int64 or use an explicit checked conversion. Use TryToNumber(this string, long, CultureInfo) when you want a non-throwing parse path and the first unrecognized token.
Attempts to convert a spelled-out number string to its numeric representation without throwing.
public static bool TryToNumber(this string words, out long parsedNumber, System.Globalization.CultureInfo culture);words System.String
The spelled-out number. Must not be null.
parsedNumber System.Int64
When this method returns, contains the parsed numeric value if successful; otherwise, 0.
culture System.Globalization.CultureInfo
The culture to use for parsing.
System.Boolean
true if the conversion was successful; otherwise, false.
This is the recommended method when the input may be invalid.
Attempts to convert a spelled-out number string to its numeric representation and reports the first unrecognized word if the conversion fails.
public static bool TryToNumber(this string words, out long parsedNumber, System.Globalization.CultureInfo culture, out string? unrecognizedWord);words System.String
The spelled-out number. Must not be null.
parsedNumber System.Int64
When this method returns, contains the parsed numeric value if successful; otherwise, 0.
culture System.Globalization.CultureInfo
The culture to use for parsing.
unrecognizedWord System.String
When this method returns false, contains the first unrecognized word found in the input.
When this method returns true, this parameter is set to null.
System.Boolean
true if the conversion was successful; otherwise, false.
This overload is useful for debugging or user-facing validation because it identifies the first token that could not be recognized.