This documentation is archived and is not being maintained.

Char.GetNumericValue Method (Char)

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

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

static double GetNumericValue (
	wchar_t c
public static double GetNumericValue (
	char 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.0.

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.

The following code example demonstrates GetNumericValue.

using namespace System;
int main()
   String^ str =  "input: 1";
   Console::WriteLine( Char::GetNumericValue( '8' ) ); // Output: "8"
   Console::WriteLine( Char::GetNumericValue( str, 7 ) ); // Output: "1"

import System.*;

public class GetNumericValueSample
    public static void main(String[] args)
        String str = "input:  1";
        Console.WriteLine(Char.GetNumericValue('8')); // Output: "8"
        Console.WriteLine(Char.GetNumericValue(str, 8)); // Output: "1"
    } //main
} //GetNumericValueSample

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0