C# Char GetNumericValue() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Char

Definition

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');
CallWhat 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

ParameterDescription
cCharacter to evaluate.
s, indexOptional string index overload.

Return Value

Return ValueDescription
double >= 0The character’s numeric value.
-1No 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);
    }
}

How It Works

  1. Digit char. Store seven as a character.
  2. Numeric double. GetNumericValue returns 7.
  3. Arithmetic. Adding 1 yields 8.
  4. 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");
    }
}

How It Works

  1. Letter A. Has no numeric value.
  2. Sentinel -1. Signals failure.
  3. Guard clause. Branch before using n as a digit.
  4. 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);
    }
}

How It Works

  1. Digit string. Three decimal digit chars.
  2. Accumulate. Add each GetNumericValue result.
  3. Sum 6. 1+2+3.
  4. 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.
Yes.

Next: GetTypeCode()

Return TypeCode.Char for this character value with System.Char.

GetTypeCode() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful