C# Exponential ("E") Format Specifier

Description

The exponential ("E") format specifier converts a number to a form of "-d.ddd?E+ddd" or "-d.ddd...e+ddd". "d" indicates a digit (0-9).

Item Value
Format specifier "E" or "e"
Supported by All numeric types.
Result Exponential notation.
Precision specifier Number of decimal digits.
Default precision specifier 6

Examples,

Value Format Formatted
1052.0329112756("E", en-US) 1.052033E+003
-1052.032911111 ("e2", en-US) -1.05e+003
-1052.032911111("E2", fr_FR) -1,05E+003

Exactly one digit always precedes the decimal point. The case of the format specifier indicates whether to prefix the exponent with an "E" or an "e".

The following NumberFormatInfo properties control the formatting.

  • NegativeSign
  • NumberDecimalSeparator
  • PositiveSign

Example


using System;// w  ww  . j av a  2 s. co  m
using System.Globalization;
class MainClass
{
   static void Main()
   {
        double value = 12345.6789;
        Console.WriteLine(value.ToString("E", CultureInfo.InvariantCulture));
        // Displays 1.234568E+004
        
        Console.WriteLine(value.ToString("E10", CultureInfo.InvariantCulture));
        // Displays 1.2345678900E+004
        
        Console.WriteLine(value.ToString("e4", CultureInfo.InvariantCulture));
        // Displays 1.2346e+004
        
        Console.WriteLine(value.ToString("E", 
                          CultureInfo.CreateSpecificCulture("fr-FR")));
        // Displays 1,234568E+004
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var