In C#, Char.GetNumericValue returns the numeric value of a character as a double. For '0'–'9' you get 0–9.
If the character has no numeric value, the method returns -1. Prefer this over subtracting '0' when you want Unicode-aware digit values.
This is a static member of System.Char. You call it with the type name, such as Char.GetNumericValue(...) or char.GetNumericValue(...). A char holds one 16-bit UTF-16 code unit.
Syntax
Pass a digit character and read the returned double.
C#
double n = Char.GetNumericValue('7');
Call
What it does
Char.GetNumericValue(c)
Numeric value, or -1.
Char.GetNumericValue(s, i)
Value of s[i].
Return type is double because some Unicode numbers are fractions.
Library declarations
C#
public static double GetNumericValue(char c);
public static double GetNumericValue(string s, int index);
Parameters
Parameter
Description
c
Character to evaluate.
s, index
Optional string index overload.
Return Value
Return Value
Description
double >= 0
The character’s numeric value.
-1
No numeric value.
C# Examples
Example 1 — Digit Seven
Convert '7' to its numeric value.
C#
using System;
class Program {
static void Main() {
char c = '7';
double n = Char.GetNumericValue(c);
Console.WriteLine(n);
Console.WriteLine(n + 1);
}
}
Output
7
8
How It Works
Digit char. Store seven as a character.
Numeric double. GetNumericValue returns 7.
Arithmetic. Adding 1 yields 8.
Not a char add. You operate on the number, not the glyph.
Example 2 — Letter Returns -1
Show the sentinel for non-numeric characters.
C#
using System;
class Program {
static void Main() {
double n = Char.GetNumericValue('A');
Console.WriteLine(n);
if (n < 0) Console.WriteLine("not numeric");
}
}
Output
-1
not numeric
How It Works
Letter A. Has no numeric value.
Sentinel -1. Signals failure.
Guard clause. Branch before using n as a digit.
Safe parsing path. Combine with IsDigit when you expect 0–9.
Example 3 — Add Digit Characters
Sum the numeric values in a digit string.
C#
using System;
class Program {
static void Main() {
string digits = "123";
double sum = 0;
foreach (char ch in digits) {
sum += Char.GetNumericValue(ch);
}
Console.WriteLine(sum);
}
}
Output
6
How It Works
Digit string. Three decimal digit chars.
Accumulate. Add each GetNumericValue result.
Sum 6. 1+2+3.
Unicode ready. Same loop works for other decimal digits if needed.
Frequently Asked Questions
The character has no numeric value.
Some Unicode numbers are fractional.
Yes. You get 0 through 9.
IsDigit is a boolean test; GetNumericValue returns the number.