DISC-O
DISC-O

Reputation: 332

Displaying a small double in in decimal, not scientific format C++ /CLR

I have doubles like 0.00006 which when displaying switch to the scientific format (something like 6E-05). I tried Math::Round(doublenumber, 5) but it cant round numbers smaller than 0.0001. So rounding 0.00016 works fine, but 0.00006 doesnt, I want to print 0.00006 and not the scientific number in my form. Any help?

Upvotes: 0

Views: 972

Answers (1)

David Yaw
David Yaw

Reputation: 27884

Use Double.ToString(String^) with the "F" format string. This forces the fixed-point format to be used.

My test program:

int main(array<System::String^>^ args)
{
    double d = 0.00006;
    Debug::WriteLine(d.ToString("f")); // Uses the default precision value, 2
    Debug::WriteLine(d.ToString("f5"));
    Debug::WriteLine(d.ToString("f9"));
    Debug::WriteLine(d.ToString("f99")); // Highest supported

    return 0;
}

Result:

0.00
0.00006
0.000060000
0.000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Upvotes: 1

Related Questions