469,117 Members | 1,488 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,117 developers. It's quick & easy.

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

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.He xNumber);
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.

Nov 16 '05 #1
1 6224
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"

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by chandra.somesh | last post: by
31 posts views Thread by Bjørn Augestad | last post: by
AdrianH
5 posts views Thread by AdrianH | last post: by
AdrianH
1 post views Thread by AdrianH | last post: by
206 posts views Thread by md | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.