[Mono-devel-list] Bug? in (float) ToString

Burton M. Strauss III BStrauss at acm.org
Sun May 4 11:19:24 EDT 2003


The results of ToString() (explicit or implicit) on double values isn't what
I would expect.  Mono seems to be ignoring the format specifier and using
"G":

using System;
public class test {
        public static void Main() {
// Expected values per
//
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconstandardnumericformatstrings.asp
// F or f Fixed-point The number is converted to a string of the form
"-ddd.ddd..." where
//        each 'd' indicates a digit (0-9). The string starts with a minus
sign if the
//        number is negative. The precision specifier indicates the desired
number of
//        decimal places. If the precision specifier is omitted, the default
numeric
//        precision given by the NumberFormatInfo is used.
                Console.WriteLine("F2:");
                Console.WriteLine("Expected 2.00: {0:F2}", 2.0);
                Console.WriteLine("Expected 2.00: {0:F2}",
2.0.ToString("#0.00"));
                Console.WriteLine("Expected 2.01: {0:F2}", 2.01);
                Console.WriteLine("Expected 2.02: {0:F2}", 2.015);
                Console.WriteLine("#0.00:");
                Console.WriteLine("Expected 2.00: {0:#0.00}", 2.0);
                Console.WriteLine("Expected 2.01: {0:#0.00}", 2.01);
                Console.WriteLine("Expected 2.02: {0:#0.00}", 2.015);
                Console.WriteLine("Explicit:");
                Console.WriteLine("Expected 2.00: {0:F2}",
2.0.ToString("#0.00"));
        }
}

F2:
Expected 2.00: 2
Expected 2.00: 2
Expected 2.01: 2.01
Expected 2.02: 2.015
#0.00:
Expected 2.00: 2
Expected 2.01: 2.01
Expected 2.02: 2.015
Explicit:
Expected 2.00: 2


Or, maybe I'm crazy.


TIA


-----Burton




More information about the Mono-devel-list mailing list