C# Exponential ("E") Format
In this chapter you will learn:
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;/*from w ww .j ava 2s .c om*/
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.
Next chapter...
What you will learn in the next chapter: