0

Anyone know how to get Engineering Notation in a cell in a datagridview similar to how excel displays with a ##0.0E+0 custom format?

myDGV.Columns(0).DefaultCellStyle.Format = "E3"

I got to here, but don't find anything to work: https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings

I've tried every combination of E, 3, and ### I can think of.

Engineering notation examples:

0.1 => 100e-3 or 100m (not 1e-1)

1,000 => 1e3 or 1k

10,000 => 10e3 or 10k (not 1e4)

i.e. the powers of 10 always follow multiples of three (https://en.wikipedia.org/wiki/Engineering_notation)

Dan
  • 89
  • 6
  • What about [The "E" and "e" custom specifiers](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings#SpecifierExponent) – Maciej Los Jul 08 '21 at 20:29
  • This: `0.###E+0` should work ;) – Maciej Los Jul 08 '21 at 20:34
  • You mention *engineering notation*: are you asking for the exponent to be a multiple of 3, so, milli, micro, nano, etc.? – Andrew Morton Jul 08 '21 at 20:37
  • Can you add a few sample inputs and outputs so that we can be sure of what you expect to see out, please? – JayV Jul 08 '21 at 21:02
  • Yes engineering notation, not scientific notation. 1,000 = 1e3 10,000 = 10e3 (not 1e4) ... 100,000 = 1e6 bonus points if e3 could be replaced k and and e6 could be replaced by M, etc. – Dan Jul 08 '21 at 21:04
  • There is nothing built into .NET to format numbers like that. You would have to write your own code to do that. – jmcilhinney Jul 09 '21 at 00:53
  • Bummer. Engineering notation is so much better than scientific! Oh welll. I'm willing to do that. What are you thinking? Display a string (instead of double), accept user entry and do the parsing / displaying myself in the backend? – Dan Jul 09 '21 at 01:08
  • Does this answer your question? [Engineering notation in C#?](https://stackoverflow.com/questions/808104/engineering-notation-in-c) – Loathing Jul 09 '21 at 04:40

0 Answers0