6

I am having value double value = 1427799000;

I would like to convert it to scientific notation where the values exponent must always 10^11 (E+11).

I have tried following but it is not working.

Console.WriteLine(value.ToString("00.##E+11", CultureInfo.InvariantCulture));

Output should be : 0.14 x 10^11 or 0.14E+11

How to convert any double value to scientific notation with fixed exponent ? Here fixed exponent is 11.

John
  • 351
  • 4
  • 16
  • Possible duplicate of http://stackoverflow.com/questions/7011236/format-c-sharp-double-to-scientfic-notation-in-powers-with-multiples-of-three – Cine Oct 03 '16 at 04:44

1 Answers1

7
double value = 1427799000;
Console.WriteLine(value.ToString("G2", CultureInfo.InvariantCulture));

//output: 1.4E+09

The General ("G") Format Specifier

The general ("G") format specifier converts a number to the most compact of either fixed-point or scientific notation, depending on the type of the number and whether a precision specifier is present.

EDIT: About your comment you can't display the scientific notation in your desirable way, it is not defined that way ! The coeficient must be greater or equal to 1 and less to 10.

For number 1.23*10^11 ->Article source

The first number 1.23 is called the coefficient. It must be greater than or equal to 1 and less than 10.

The second number is called the base . It must always be 10 in scientific notation. The base number 10 is always written in exponent form. In the number 1.23 x 10^11 the number 11 is referred to as the exponent or power of ten.

mybirthname
  • 17,949
  • 3
  • 31
  • 55
  • Thanks however I need the output to fixed exponent. Here exponent is 9, I want it to fixed 11. output should be `0.14E+11` How to do that? – John Oct 03 '16 at 03:39
  • 2
    @John Your way of representing is not correct and not by definition. – mybirthname Oct 03 '16 at 03:59
  • Thanks for the article source. I researched further more and found that my representation of 1427799000 `0.14E+11` is not correct. It should be `1.43E+09` or `1.43 x 10^9`. – John Oct 03 '16 at 06:46
  • @John you can mark the answer as correct in this case. – mybirthname Oct 03 '16 at 07:26