Bug in Decimal.Parse()

  • Thread starter Thread starter GP
  • Start date Start date
G

GP

Decimal.Parse("100,5") returns 1005 when it should throw an
InvalidFormatException. The locale is US therefore the "," is a thousand
separator. Even if the parser confused it for the decimal separator it
should return 100.5. Maybe this bug is already logged but I couldn't find it
on MSDN.
 
I would assume that it is simply ignoring the , characters in the string
.....

are you passing a NumberFormatInfo object or just calling
Double.Parse(string) ?

Indicates that the numeric string can have group separators; for example,
separating the hundreds from the thousands. Valid group separator characters
are determined by the NumberGroupSeparator and CurrencyGroupSeparator
properties of NumberFormatInfo and the number of digits in each group is
determined by the NumberGroupSizes and CurrencyGroupSizes properties of
NumberFormatInfo.
 
To submit, the rotor code demonstrates the character is simply
skipped. It's relative location or it's scale is not checked to make
sure it is on a valid boundary. So Greg's notes are correct.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers


Greg Young said:
I would assume that it is simply ignoring the , characters in the string
....

are you passing a NumberFormatInfo object or just calling
Double.Parse(string) ?

Indicates that the numeric string can have group separators; for example,
separating the hundreds from the thousands. Valid group separator characters
are determined by the NumberGroupSeparator and CurrencyGroupSeparator
properties of NumberFormatInfo and the number of digits in each group is
determined by the NumberGroupSizes and CurrencyGroupSizes properties of
NumberFormatInfo.
 
A bug indeed: Decimal.Parse("1,1,1,1,1,1") returns 111111.
How to submit this bug to Microsoft? I also have spotted a logical mistake
in the C# specs (sec. 7.11.2) which result in wrong expression evaluation
but I don't know where to send this stuff.

Justin Rogers said:
To submit, the rotor code demonstrates the character is simply
skipped. It's relative location or it's scale is not checked to make
sure it is on a valid boundary. So Greg's notes are correct.
 
Back
Top