Ok, Someone tell me what I'm doing wrong. The statement below is
returning 527.0 in v, instead of the expected 215. Am I missing
something?
double v;
if (Double.TryParse("0d7", NumberStyles.HexNumber,
NumberFormatInfo.InvariantInfo, out v))
{
......
}
Thanks,
Greg
Greg,
It's not returning anything for me, actually, it throws an exception.
In .NET 2.0, you can not use the hex modifier on floating point values.
If you are using .NET 2.0, then I would recommend using the TryParse
method on the Int32 structure. If not, then I would call the Parse method,
and catch the exception.
Then I would convert the int to a double through a cast.
Hope this helps.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Ok, Someone tell me what I'm doing wrong. The statement below is
> returning 527.0 in v, instead of the expected 215. Am I missing
[quoted text clipped - 11 lines]
>
> Greg
Greg Wilkerson - 12 Dec 2005 17:39 GMT
That's interesting. I thought I was on .NET 2.0. I'll have to
upgrade that. Did you get it to work properly using the Int32
structure, or did you try? I'll get my .NET upgraded and try the
Int32.
Thanks.
>Greg,
>
[quoted text clipped - 8 lines]
>
> Hope this helps.
Nicholas Paldino [.NET/C# MVP] - 12 Dec 2005 17:41 GMT
Greg,
It worked fine when I ran this using the TryParse method on Int32.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> That's interesting. I thought I was on .NET 2.0. I'll have to
> upgrade that. Did you get it to work properly using the Int32
[quoted text clipped - 16 lines]
>>
>> Hope this helps.
Greg Wilkerson - 12 Dec 2005 19:50 GMT
Well, I thought there was a reason I had not upgraded to .NET 2.0; VS
2003 won't use it.
So, I'll just catch a parse exception. Th'at's probably all the
TryParse does, anyway.
On a side note, I did think it was odd to provide a hex conversion for
a double.
Thanks for you help.
Greg
>Greg,
>
> It worked fine when I ran this using the TryParse method on Int32.
Nicholas Paldino [.NET/C# MVP] - 12 Dec 2005 21:00 GMT
Greg,
Actually, the TryParse does not just catch the exception. The whole
point of the TryParse method is to reduce the overhead involved with having
to catch an exception if the string can not be parsed.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Well, I thought there was a reason I had not upgraded to .NET 2.0; VS
> 2003 won't use it.
[quoted text clipped - 12 lines]
>>
>> It worked fine when I ran this using the TryParse method on Int32.