C# Exponential ("E") Format Specifier

The Exponential ("E") format specifier in C# converts a number to scientific notation. It represents numbers in the form of a coefficient multiplied by a power of 10, making it ideal for very large or very small numbers.

Syntax

The exponential format specifier has the following syntax −

"E" or "e"
"En" or "en" (where n specifies decimal places)

The resulting string format is −

"-d.ddd...E+ddd" or "-d.ddd...e+ddd"

Where "d" represents a digit (0-9). The "E" or "e" separates the coefficient from the exponent.

Exponential Format Structure Coefficient E/e Exponent 3.45 E +003 Example: 3.45E+003 = 3.45 × 10³ = 3450

Basic Exponential Formatting

Example

using System;
using System.Globalization;

class Demo {
    static void Main() {
        double d = 3452.7678;
        Console.WriteLine(d.ToString("E", CultureInfo.InvariantCulture));
        Console.WriteLine(d.ToString("E10", CultureInfo.InvariantCulture));
        Console.WriteLine(d.ToString("e", CultureInfo.InvariantCulture));
        Console.WriteLine(d.ToString("e10", CultureInfo.InvariantCulture));
    }
}

The output of the above code is −

3.452768E+003
3.4527678000E+003
3.452768e+003
3.4527678000e+003

Precision Control

You can control the number of decimal places in the coefficient by specifying a precision specifier −

Example

using System;
using System.Globalization;

class Demo {
    static void Main() {
        double value = 123456.789;
        Console.WriteLine("E0: " + value.ToString("E0", CultureInfo.InvariantCulture));
        Console.WriteLine("E2: " + value.ToString("E2", CultureInfo.InvariantCulture));
        Console.WriteLine("E4: " + value.ToString("E4", CultureInfo.InvariantCulture));
        Console.WriteLine("E6: " + value.ToString("E6", CultureInfo.InvariantCulture));
    }
}

The output of the above code is −

E0: 1E+005
E2: 1.23E+005
E4: 1.2346E+005
E6: 1.234568E+005

Working with Very Large and Small Numbers

Example

using System;
using System.Globalization;

class Demo {
    static void Main() {
        double veryLarge = 1.23456789e15;
        double verySmall = 1.23456789e-8;
        
        Console.WriteLine("Large number:");
        Console.WriteLine("E3: " + veryLarge.ToString("E3", CultureInfo.InvariantCulture));
        Console.WriteLine("e3: " + veryLarge.ToString("e3", CultureInfo.InvariantCulture));
        
        Console.WriteLine("\nSmall number:");
        Console.WriteLine("E3: " + verySmall.ToString("E3", CultureInfo.InvariantCulture));
        Console.WriteLine("e3: " + verySmall.ToString("e3", CultureInfo.InvariantCulture));
    }
}

The output of the above code is −

Large number:
E3: 1.235E+015
e3: 1.235e+015

Small number:
E3: 1.235E-008
e3: 1.235e-008

Comparison with Other Format Specifiers

Format Specifier Example Output Use Case
Exponential E2 1.23E+003 Scientific notation
Fixed-point F2 1234.57 Regular decimal numbers
General G 1234.5678 Automatic format selection

Common Use Cases

  • Scientific calculations: Representing measurements in physics, chemistry, and engineering.

  • Very large numbers: Population statistics, astronomical distances, molecular counts.

  • Very small numbers: Microscopic measurements, precision tolerances, probability values.

  • Data analysis: Displaying statistical results that span multiple orders of magnitude.

Conclusion

The exponential ("E") format specifier in C# converts numbers to scientific notation, making it ideal for representing very large or very small values. Use "E" for uppercase or "e" for lowercase notation, and specify precision to control the number of decimal places in the coefficient.

Updated on: 2026-03-17T07:04:35+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements