473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

string format number of leading 0 in exponent in scientific notation

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
2 3453
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: jose luis fernandez diaz | last post by:
Hi, My OS is: cronos:jdiaz:tmp>uname -a HP-UX cronos B.11.11 U 9000/800 820960681 unlimited-user license I compile in 64-bits mode the program below:
1
by: adahili | last post by:
Hi, I use cout to print numbers in scientific notation. I noticed that a number like 12.34 is sometimes (compiler-dependent) printed as 1.234e+1 or 1.234e+01 or 1.234e+001. Since I know the...
1
by: Nick | last post by:
Well, the project I am working on has now come to a screeching halt! I have been developing a program that heavily utilizes ADO.NET record sets. To generate reports, I convert the recordset to XML,...
12
by: YLD | last post by:
Hi, How could I copy a float to a string? For example: float number = 12.34; char numberstring; *introduce some magic code here* resulting in numberstring ==
5
by: Dennis Myrén | last post by:
Hi. Is there a way to make sure that float, double and decimal data types never will be presented in a scientific notation? I have tried to round(Math.Round) float's to 7 decimals, double's to...
16
by: John Salerno | last post by:
My initial feeling is that concatenation might take longer than substitution, but that it is also easier to read: def p(self, paragraph): self.source += '<p>' + paragraph + '</p>\n\n' vs. ...
6
by: Darren Dale | last post by:
Does anyone know if it is possible to represent a number as a string with engineering notation (like scientific notation, but with 10 raised to multiples of 3: 120e3, 12e-6, etc.). I know this is...
4
by: bobm2005 | last post by:
Whatever format I try in Printf, an 'E' format number nearly always has a leading non-zero:- 1.2345E7 -9.3456E8 etc. Is it possible to force it (printf) always to have leading zero? ...
3
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, By default, the "g" format specifier seems to use 2 digits in the exponent if it decides to use the scientific format. I.e., Double.ToString("g"). How do I control the number of...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.