[Mono-devel-list] Bug? in (float) ToString
yoros at wanadoo.es
yoros at wanadoo.es
Sun May 4 16:23:45 EDT 2003
On Sun, May 04, 2003 at 10:19:24AM -0500, Burton M. Strauss III wrote:
> 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.
That bug is not in float formatter (I think so). Try to use:
Console.WriteLine(2.00.ToString("F2");
The bug may be in String.Format that should call X.ToString("F2") when
{0:F2} is in the format string.
Please, test it in MS.NET and file a bug in bugzilla.ximian.com (corlib)
so we have enough information to fix it.
Regards,
Pedro
--
Pedro Martínez Juliá
\ yoros at terra.es
)| yoros at wanadoo.es
/ http://yoros.cjb.net
Socio HispaLinux #311
Usuario Linux #275438 - http://counter.li.org
GnuPG public information: pub 1024D/74F1D3AC
Key fingerprint = 8431 7B47 D2B4 5A46 5F8E 534F 588B E285 74F1 D3AC
More information about the Mono-devel-list
mailing list