By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,052 Members | 1,303 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,052 IT Pros & Developers. It's quick & easy.

string format number of leading 0 in exponent in scientific notation

P: n/a
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

Sep 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
you can use the following:

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

hth

"Robert Ludig" <sc******************@gmx.deschrieb im Newsbeitrag
news:11**********************@i3g2000cwc.googlegro ups.com...
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

Sep 25 '06 #2

P: n/a
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 ?

Christof Nordiek schrieb:
you can use the following:

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

hth

"Robert Ludig" <sc******************@gmx.deschrieb im Newsbeitrag
news:11**********************@i3g2000cwc.googlegro ups.com...
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
Sep 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.