Export (0) Print
Expand All

Char.GetNumericValue Method (Char)

.NET Framework 1.1

Converts the specified numeric Unicode character to a double-precision floating point number.

[Visual Basic]
Overloads Public Shared Function GetNumericValue( _
   ByVal c As Char _
) As Double
public static double GetNumericValue(
 char c
public: static double GetNumericValue(
 __wchar_t c
public static function GetNumericValue(
   c : Char
) : double;


A Unicode character.

Return Value

The numeric value of c if that character represents a number; otherwise, -1.0.


For example, if c is '5', the return value is 5. However, if c is 'z', the return value is -1.

A character has an associated numeric value if and only if it is a member of one of the following categories in UnicodeCategory: DecimalDigitNumber, LetterNumber, or OtherNumber.


[Visual Basic, C#, C++] The following sample demonstrates GetNumericValue.

[Visual Basic] 
Imports System

Module GetNumericValueSample

    Sub Main()

        Dim str As String
        str = "input: 1"

        Console.WriteLine(Char.GetNumericValue("8"c))       ' Output: "8"
        Console.WriteLine(Char.GetNumericValue(str, 7))     ' Output: "1"

    End Sub

End Module

using System;

public class GetNumericValueSample {
    public static void Main() {
        string str = "input: 1";

        Console.WriteLine(Char.GetNumericValue('8'));        // Output: "8"
        Console.WriteLine(Char.GetNumericValue(str, 8));    // Output: "1"

#using <mscorlib.dll>
using namespace System;

int main() {
   String* str = "input: 1";

   Console::WriteLine(Char::GetNumericValue('8'));    // Output: "8"
   Console::WriteLine(Char::GetNumericValue(str, 7)); // Output: "1"

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Char Structure | Char Members | System Namespace | Char.GetNumericValue Overload List

© 2014 Microsoft