|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
string format number of leading 0 in exponent in scientific notationWhen 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 you can use the following:
string.Format("{0:0.00000000E+0}",20000); hth Show quote "Robert Ludig" <schwertfischtromb***@gmx.de> schrieb im Newsbeitrag news:1159168462.395579.129330@i3g2000cwc.googlegroups.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 > 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: Show quote > you can use the following: > > string.Format("{0:0.00000000E+0}",20000); > > hth > > "Robert Ludig" <schwertfischtromb***@gmx.de> schrieb im Newsbeitrag > news:1159168462.395579.129330@i3g2000cwc.googlegroups.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 > > |
|||||||||||||||||||||||