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)

public static double GetNumericValue (
	char c
)
public static double GetNumericValue (
	char c
)
public static function GetNumericValue (
	c : char
) : double
Not applicable.

Parameters

c

A Unicode character.

Return Value

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

The c parameter must be the Char representation of a numeric value. 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 System;

public class GetNumericValueSample {
	public static void 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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Show: