int.parse and double.parse yield different value for hex string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Why do I get different values for the same hex string when parsing to an
integer versus a double? See the follwoing code snippet:

using System;
using System.Collections;
using System.Threading;

public class MyClass
{
public static void Main()
{
double d;
int n;

string str;
str = "8D";
n = int.Parse(str,System.Globalization.NumberStyles.HexNumber);
Console.WriteLine("n is {0}", n);
d = double.Parse(str,System.Globalization.NumberStyles.HexNumber);
Console.WriteLine("d is {0}", d);
Thread.Sleep(5000);
}
}

The integer vlaue is what I expected, 141, whereas the double result is 100.
 
Hi Kevin,

I'm not sure why it returns the wrong number for double.Parse
However, in Framework 2.0 double.Parse causes an argument exception "NumberStyles.AllowHexSpecifier is not supported on floating point data types"
 
Back
Top