471,350 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Number of digits in exponent with "g" format?

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
Jul 17 '08 #1
3 4205
Ray Mitchell wrote:
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.
Something like x.ToString("e") or x.ToString("0.00000000e+000") will
always use scientific format with 3 digits in the exponent.

Arne
Jul 18 '08 #2


"Arne Vajhøj" wrote:
Ray Mitchell wrote:
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.

Something like x.ToString("e") or x.ToString("0.00000000e+000") will
always use scientific format with 3 digits in the exponent.

Arne
Yes, but I don't always want scientific. I want it to be done like "g" does
it except that when it does "choose" scientific, it uses 3 digits of exponent
instead of 2.
Jul 18 '08 #3
Ray Mitchell wrote:
"Arne Vajhøj" wrote:
>Ray Mitchell wrote:
>>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.
Something like x.ToString("e") or x.ToString("0.00000000e+000") will
always use scientific format with 3 digits in the exponent.

Yes, but I don't always want scientific. I want it to be done like "g" does
it except that when it does "choose" scientific, it uses 3 digits of exponent
instead of 2.
Unfortunately there does not seem to be support for that in
..NET (NumberFormatInfo).

You will have to find the borders and write some code
that tests for inside/outside and call code accordingly.

Arne
Jul 19 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by martin.mrazek | last post: by
3 posts views Thread by John H. | last post: by
reply views Thread by moondog | last post: by
1 post views Thread by ADA | last post: by
6 posts views Thread by psbasha | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.