string format number of leading 0 in exponent in scientific notation

R

Robert Ludig

When I format a number to a string in scientific notation:

string.Format("{0:E}",20000);

I get the following string (culture de-DE):

2,000000E+003

How can I format scientific notation in a way that no leading 00 are
inserted for the exponent, so the above would look like this:

2,000000E+3
 
B

bonk

This way I would have to specify the precision in the formatstring. If
I wanted to dynamically adjust the precision I would always have to
build a "0.000000" string with the amount of "0"s representing the
precision I want. I find that somewhat odd and it cutters the code. Is
there another, more convienient way to achieve the desired effect.
Maybe something like

string.Format("{0:8E+0}",20000); // doesn't work, but is there a
similar syntax ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top