none
Bug in double parse RRS feed

  • Question

  • Why does Double.TryParse accept 1,,,,,,2 as 12? Seems like the parse method is ignoring the NumberGroupSizes options (which is 3 in english). Note it also converts 1,2=>12; 1,2,3,4 => 1234; 1,,2,,3,,,,,4=>1234 etc. This seems like a bug to me.

    Thanks
    Monday, July 13, 2009 2:59 PM

Answers

All replies

  • Hi
      I think it is the other way around, i am not sure. I think the TryParse is trying to parse the input string, takes the values which can be joined to gether to a double, joins it and make the double. So the TryParse method is removing the illegal charecters(in terms of integer types) and makes a double value. I think it is the power of the implementation of TryParse method.


    -- Thanks Ajith R [Mark the best posts as Answers.]
    Monday, July 13, 2009 5:29 PM
  • Hi,

    I also agree with Ajith, it is a feature more than a bug to me.

    Regards,
    Vinil
    Monday, July 13, 2009 5:32 PM
  • You get the same behavior with double or int. 1,,,,,,,,,,2.3 = 12.3 how is that a feature? There's a property in the NumberFormatInfo that specifies how many numbers are supposed to constitute a group. For English it's 3. I would expect that 1,200.5 would be 1200.5 and that 1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,3.4 would throw a format exception. It does not have 3 numbers in the group. How is that a feature?
    Tuesday, July 14, 2009 12:00 AM
  • By the same token "1, 2" is not 12. I understand that it's ignoring the commas but there are properties in the number format that is not supposed to allow that. NumberDecimalDigits seems to only be valid for output not input but that's not stated anywhere in the documentation. I still am not sure why this is a feature.
    Tuesday, July 14, 2009 12:07 AM
  • In fact if you put 1,2 and 2,3 in cells in excel then try to add the values you get #VALUE!. But of course if I have 3 digits in the cell it's treated as a number.
    Tuesday, July 14, 2009 12:11 AM
  • Post feature change requests to connect.microsoft.com. 

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, July 17, 2009 11:51 AM
    Tuesday, July 14, 2009 4:43 AM
    Moderator