C# | Char.GetNumericValue() Method
In C#, Char.GetNumericValue() is a System.Char struct method which is used to convert a numeric Unicode character into a double-precision floating-point number. The numeric value must belong to UnicodeCategory, i.e DecimalDigitNumber, LetterNumber, or OtherNumber. This method can be overloaded by passing different type and number of arguments to it.
- Char.GetNumericValue(String, Int32) Method
- Char.GetNumericValue(Char) Method
Char.GetNumericValue(String, Int32) Method
This method is used to convert the numeric Unicode character at the specified position in a specified string to a double-precision floating point number. Character position in a string always starts from zero.
Syntax:
public static double GetNumericValue(String str, int index);
Parameters:
str: It is the specified string of type System.String.
index: It represents the character position in the string str and type of this parameter is System.Int32.
Return Type: If the character is represented by the number, then this method returns a numeric value at position index in str otherwise it returns -1. The return type of this method is System.Double.
Exceptions:
- If the value of the given string str is null then this method will give ArgumentNullException.
- If the index is less than zero or greater than the last position in str, then this method will give ArgumentOutOfRangeException.
Example:
using System;
class GeeksforGeeks {
public static void Main()
{
double output;
string str = "geeks213" ;
output = Char.GetNumericValue(str, 4);
Console.WriteLine(output);
output = Char.GetNumericValue(str, 7);
Console.WriteLine(output);
}
}
|
Char.GetNumericValue(Char) Method
This method is used to convert the specified Unicode character into a double-precision floating-point number.
Syntax:
public static double GetNumericValue(Char ch);
Parameter:
ch: It is the Unicode character which is to be converted into double-precision floating-point number.
Return Type: If a character represents a number, then this method returns the numeric value of ch, otherwise it returns -1.0. The return type of this method is System.Double.
Example:
using System;
class GeeksforGeeks {
public static void Main()
{
Console.WriteLine(Char.GetNumericValue( '9' ));
Console.WriteLine(Char.GetNumericValue( 'z' ));
}
}
|
Reference: https://docs.microsoft.com/en-us/dotnet/api/system.char.getnumericvalue?view=netframework-4.7.2
Last Updated :
01 Feb, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...