473,770 Members | 5,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3487
you can use the following:

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

hth

"Robert Ludig" <sc************ ******@gmx.desc hrieb im Newsbeitrag
news:11******** **************@ i3g2000cwc.goog legroups.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.desc hrieb im Newsbeitrag
news:11******** **************@ i3g2000cwc.goog legroups.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
2975
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
4902
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 expected number of digits for the exponent, I would like to control it. I can control the width of the base part but not the exponent. Does anybody know how to set the width of the exponent? TIA.
1
8865
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, and then apply an XSLT to transform the XML into HTML. This works great (or did) until today. I just found out that the "number-format" command in XSLT can't handle scientific notation! So when I try to format these numbers I just get "NaN" on...
12
12020
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
17663
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 15 and decimals to 28 decimals, but that does not help. And the System.Globalization.NumberFormatInfo class does not seem to provide a such function.
16
1849
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. def p(self, paragraph):
6
6670
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 possible with the decimal.Decimal class, but repeatedly instantiating Decimals is inefficient for my application (matplotlib plotting library). If it is not currently possible, do you think the python devs would be receptive to including support...
4
3218
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? Thus, the above becomes:-
3
4331
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 exponent digits used without affecting the operation of "g" in any other way? I need it to use 3 digits instead. Thanks, Ray
0
10225
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.