467,118 Members | 994 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,118 developers. It's quick & easy.

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
  • viewed: 8620
Share:
1 Reply
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by aevans1108@yahoo.com | last post: by
3 posts views Thread by =?Utf-8?B?U2NvdHQ=?= | last post: by
1 post views Thread by Lee | last post: by
2 posts views Thread by Derek Hart | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.