I have a series of numbers that can be either large integers, or very small decimals. I would like numbers with more than four digits to be displayed in scientific notation.
At first, I considered a custom number format 0.000E+0, but that puts E+0 at the end of any numbers with less than four digits.
While searching, I was suggested using the General formatter G4, but that doesn't turn small decimal numbers into Scientific Notation, for example, 0.001234 remains as 0.001234 instead of becoming 1.234E-3 as I would expect.
I need a number format string that fulfills the following conditions:
0 -> 0
1234 -> 1234
12348 -> 1.235E3
0.123 -> 0.123
0.1234 -> 1.234E-1
0.001234 -> 1.234E-3
A passive number format string that would produce that kind of active parsing might be a tall order. But if there's any way that using an extension method would work for your use case then it would be fairly simple to make one.
Usage
Here's a first pass that produces the format in your post:
Console app