1

I make such formatting:

 str += String.Format("{0,-25}", doubl);

I need my numbers to be divided by spaces, that's why I use {0,-25}.

But sometimes I get numbers like 2.15083096934631E-05

How to get traditional numbers like 0,000021508 , without "E-05" ?

The value of doubl is like 0.000021436573129839587

146 percent Russian
  • 2,016
  • 2
  • 14
  • 20

4 Answers4

2

Use the The "0" Custom Specifier:

str = doubl1.ToString("0.0000000");
Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
2

Try double.ToString("format") (F - Fixed-point)

str=doubleValue.ToString("F10");
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
0

You can format the output by passing in F or N to the ToString(), to represent more decimal points i think you will have to specify something like N15 (find the suitable limit you need depending on your values) but the issue here is trailing 0 after your actual number

[double value].ToString("N15") // this should output without the exponent sign

To avoid trailing zeros you just need to Trim

[double value].ToString("N15").TrimEnd('0');
V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
0

All the Answers prior to mine were fine but for me, I had a very ugly problem. My 'Answer' would be filled by Zero's and it made the answer very bulky if there was only 5 Zeros needed. I came up with this:

double Q = ((1000 * 1000) * (2 * 2));
double Answer = ((Q * 199) / 2);
this.AnswerTBox1.Text = String.Format("{0:F" + Answer.ToString().Length + "}", Answer);

This tidy's up the 'Uglyness' of unnecessary Zeros.

All the Best

Chris

Rusty Nail
  • 2,692
  • 3
  • 34
  • 55