Char::GetNumericValue Method (String, Int32)
Converts the numeric Unicode character at the specified position in a specified string to a double-precision floating point number.
Assembly: mscorlib (in mscorlib.dll)
Return Value
Type: System::DoubleThe numeric value of the character at position index in s if that character represents a number; otherwise, -1.
| Exception | Condition |
|---|---|
| ArgumentNullException | s is nullptr. |
| ArgumentOutOfRangeException | index is less than zero or greater than the last position in s. |
The s parameter must be the string representation of a numeric value. For example, if the character at position index in s is "5", the return value is 5. However, if the character at position index in s is "z", the return value is -1.
Character positions in a string are indexed starting from zero.
A character has an associated numeric value if and only if it is a member of one of the following UnicodeCategory categories: DecimalDigitNumber, LetterNumber, or OtherNumber.
If the Char object at position index is the first character of a valid surrogate pair, the GetNumericValue method determines whether the surrogate pair forms a numeric digit. For example, the Aegean numbering system consists of code points U+10107 through U+10133. The following example uses the ConvertFromUtf32 method to instantiate a string that represents each Aegean number. As the output from the example shows, the GetNumericValue method returns the correct numeric value if it is passed the high surrogate of an Aegean number. However, if it is passed the low surrogate, it considers only the low surrogate in isolation and returns -1.
The following code example demonstrates GetNumericValue.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.