[Mono-list] IntegerFormatter
Nick Drochak
ndrochak@gol.com
Tue, 27 Nov 2001 21:55:54 +0900
Yeah, that's what I thought at first too. However, when you use
ToString() with a second parameter in VS.Net like:
sbyte sb = -128;
String s = sb.ToString("n", NumberFormatInfo.InvariantInfo)
Then s is "(128.00)".
An example from MSDN (NumberFormatInfo.NumberNegativePattern Property)
has something similar: using System; using System.Globalization; class
SamplesNumberFormatInfo {
public static void Main() {
// Create a new NumberFormatinfo instance.
NumberFormatInfo myNfi = new NumberFormatInfo();
// Take a negative value.
Int64 myInt = -1234;
// Display the value with default formatting.
Console.WriteLine( "Default \t:\t{0}", myInt.ToString( "N", myNfi
) );
// Display the value with other patterns.
for ( int i = 0; i <= 4; i++ ) {
myNfi.NumberNegativePattern = i;
Console.WriteLine( "Pattern {0}\t:\t{1}",
myNfi.NumberNegativePattern, myInt.ToString( "N", myNfi ) );
}
}
}
/*
Output:
Default : (1,234.00)
Pattern 0 : (1,234.00)
Pattern 1 : -1,234.00
Pattern 2 : - 1,234.00
Pattern 3 : 1,234.00-
Pattern 4 : 1,234.00 -
*/
> -----Original Message-----
> From: Derek Holden [mailto:dsh2120@draper.com]
> Sent: Tuesday, November 27, 2001 9:33 PM
> To: Nick Drochak
> Subject: Re: IntegerFormatter
>
>
> Hey Nick,
>
> I think the error may be in the SByte test. Format type "n"
> is listed in the EMCA IFormattable doc as:
>
> n Number Format: Used for strings in the following form:
>
> [-]d,ddd,ddd.dd...d
>
> The minus sign ("-") appears only if the number is negative.
> At least one non-zero digit (d) precedes the decimal
> separator ("."). The precision specifier determines the
> number of decimal places (dd.d). If the precision specifier
> is omitted, NumberFormatInfo.NumberDecimalDigits determines
> the number of decimal places in the string. Results are
> rounded to the nearest representable value when necessary.
> The NumberGroupSizes, NumberGroupSeparator, and
> NumberDecimalSeparator members of a NumberFormatInfo supply
> the size and separator for digit groupings, and decimal
> separator, respectively.
>
> I know in currency format and percent format that parenthesis
> are used for negative values, but that is determined by
> NumberFormatInfo.CurrencyNegativePattern and
> NumberFormatInfo.PercentNegativePattern, which are defined in
> the NumberFormatInfo spec.
>
> ----- Original Message -----
> From: "Nick Drochak" <ndrochak@gol.com>
> To: <dholden@draper.com>
> Cc: <mono-list@ximian.com>
> Sent: Tuesday, November 27, 2001 7:20 AM
> Subject: IntegerFormatter
>
>
> > Derek,
> >
> > The Nunit test for Sbyte is failing, but the problem seems to be in
> > IntegerFormatter.cs. When the test does ToString("n",
> > NumberFormatInfo.InvariantInfo) on an Sbyte with value
> -128, it should
> > produce "(128.00)". However, instead we get "-128.00".
> >
> > In fact, from the code it looks like all the integral types
> never get
> > formatted with the parentheses. Can you have a look at
> this? Sorry I
> > don't have a patch for you myself :)
> >
> > Regards,
> > Nick
> >
> >
> >
>
>
>