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

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.
 
M

Morten Wennevik

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top