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:
// C# program to illustrate the // Char.GetNumericValue(String, Int32) Method using System; class GeeksforGeeks { // Main method public static void Main() { // declaration of datatype double output; string str = "geeks213"; // provide numeric value of position 4 output = Char.GetNumericValue(str, 4); Console.WriteLine(output); // provide numeric value of position 7 output = Char.GetNumericValue(str, 7); Console.WriteLine(output); } } |
-1 3
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:
// C# program to illustrate the // Char.GetNumericValue(Char) Method using System; class GeeksforGeeks { // Main method public static void Main() { // using Char.GetNumericValue(char method) Console.WriteLine(Char.GetNumericValue('9')); Console.WriteLine(Char.GetNumericValue('z')); } } |
9 -1
Reference: https://docs.microsoft.com/en-us/dotnet/api/system.char.getnumericvalue?view=netframework-4.7.2
Recommended Posts:
- Difference between Method Overriding and Method Hiding in C#
- C# | String.Contains() Method
- C# | Math.Max() Method
- Decimal.Add() Method in C#
- C# | Math.Min() Method
- Stack.Pop() Method in C#
- DateTimeOffset.Add() Method in C#
- Extension Method in C#
- Stack.Contains() Method in C#
- C# | CopyTo() Method
- C# | Trim() Method
- C# | Method Parameters
- C# | Remove() Method
- C# | IndexOfAny() Method
- Queue.Contains() Method in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



