[Mono-list] number formatting

Derek Holden dsh2120@draper.com
Wed, 10 Oct 2001 08:56:08 -0400


I just added the number formatting for the integer types if anyone wants to
play with it. I have a test that does

  string[] formats = {
    "C", "C0", "C1", ... "C99",
    "D", "D0", "D1", ... "D99",
    "E", "E0", "E1", ... "E99",
    "F", "F0", "F1", ... "F99",
    "G", "G0", "G1", ... "G99",
    "N", "N0", "N1", ... "N99",
    "P", "P0", "P1", ... "P99",
    "X", "X0", "X1", ... "X99"
   };

   for (int n = -10000; n < 10000; n++)
    foreach (string format in formats)
      if ( [microsoft's] n.ToString(format) != [mono's] n.ToString(format) )
say something;

For all ints, uints, shorts, ushorts, longs, ulongs, sbytes, and bytes. It
seems to be passing all the tests. If there is anyone who is interested in
making an NUnit test for all that I'll send my test to them. I haven't
played w/ NUnit enough to know if there would be an easier way other than a
million lines of Assert(n.ToString("C4"), "$42,321.0000")'s.

It also seems to be using the NumberFormatInfo stuff properly, but that'd be
even harder to write a test for. There's a lot you can do with the
NumberFormatInfo patterns and symbols to get custom printings of currency
and percents and stuff, but you have to set up a FormatProvider and lay out
patterns. If anyone is interested in NUnit'ing that I can send some tests I
did with it.

I was planning on working on the decimal types next.