Number of digits in exponent with "g" format?

R

Ray Mitchell

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
 
A

Arne Vajhøj

Ray said:
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
 
R

Ray Mitchell

Arne Vajhøj said:
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.
 
A

Arne Vajhøj

Ray said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top