473,394 Members | 1,852 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,394 software developers and data experts.

Double ToString format string

I'm trying to format a double with this behavior:

1) should only show 8 characters (character count before and after
decimal added together).
2) if greater than 7 characters to the left of the decimal, should
display in scientific notation.
3) if 7 characters or less to the left of the decimal, should round the
characters to the right of the decimal so only 8 characters are shown.

Anyone have any idea how to do this with the Double.ToString() format
string? Obviously using "e" as the format argument to ToString() will
always produce scientific notation, but that's not what I want in all
cases. Examples of what I'd like are:

orignal value desired value
------------- -------------
123.0 123.0
1234567.891 1234567.9
123456789.987 1.23e+08
123.456789123 123.45679

Thanks in advance for any help

--Ed
Nov 16 '05 #1
1 8899
Ed
Use the string method indexof with the decimal as an argument. This will tell you where the decimal is and then you can decide what to do from there, if the indexof returns 9 or greater then you need to convert to sci not, but if index of is 8 or less then you need to do your rounding algo.
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
2
by: Rod Brick | last post by:
I'm trying to print a Double in straight decimal form, not exponential. I can't seem to accomplish this. This seems like it should be simple enough. The output I'm looking for is "0.00001", not...
3
by: Boz | last post by:
Hi, I am trying to use string.Format() to output the value of a double. double da = 100000000000.99994; double db = 100000000000.9994; double dc = 100000000000.994; double dd =...
5
by: Markus Kling | last post by:
"double.Parse(double.MaxValue.ToString())" yields the following Exception: Value was either too large or too small for a Double. at System.Number.ParseDouble(String value, NumberStyles options,...
9
by: Coleen | last post by:
Hi All :-) I found the way to get my column sum (Thanks Cor I did it a little different, but the result is what I wanted) I used: dt_stat_report_3b.Columns.Add(New DataColumn("Sum",...
12
by: ThunderMusic | last post by:
Hi, We have a part of our application that deals with millions of records and do some processing of them. We've achieved a pretty good performance gain by developping a custom DateTime.ToString...
3
by: =?Utf-8?B?U2NvdHQ=?= | last post by:
Hello, I would like to convert a double to a string and have the resulting string contain all of the original values after the decimal place. Currently, the problem that I am having is that the...
1
by: Lee | last post by:
Hi, I am trying to convert a double to a string using the following format;- double = 1.01 string = 01.0100 or
2
by: Derek Hart | last post by:
I have a double stored in a DataTable: dt.Rows(i)(MergeFieldName) I want to format this and store it into a string. I have formatting stored in a database, such as "$#,##0.00"
2
by: Lior Bobrov | last post by:
Hi ... How to convert a variable of type Double to String , *preserving* the original value of the Double variable , as is , in a short (convenient) way ? For example , if there are two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.