user2089789
user2089789

Reputation:

Convert double to scientific notation with specific number after decimal points

I want to convert double to scientific notation like this:

-0.00752382528 => -.752383E-1

can i do this with .ToString() or Regex?

Upvotes: 15

Views: 18878

Answers (1)

D Stanley
D Stanley

Reputation: 152626

You can either use the standard format string for scientific notation:

(-0.00752382528).ToString("E5")   // returns "-7.52383E-003"

or if you don't want the leading zeros in the exponent, use a custom string:

(-0.00752382528).ToString("0.00000E0")   // returns "-7.52383E-3"

Upvotes: 21

Related Questions