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 5 5549
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Greg Wilkerson" <gr***********@charter.net> wrote in message
news:jk********************************@4ax.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 something?
double v;
if (Double.TryParse("0d7", NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo, out v)) { ...... }
Thanks,
Greg
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.
On Mon, 12 Dec 2005 12:21:27 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote: 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.
Greg,
It worked fine when I ran this using the TryParse method on Int32.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Greg Wilkerson" <gr***********@charter.net> wrote in message
news:2b********************************@4ax.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 structure, or did you try? I'll get my .NET upgraded and try the Int32.
Thanks.
On Mon, 12 Dec 2005 12:21:27 -0500, "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote:
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.
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
On Mon, 12 Dec 2005 12:41:43 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote: Greg,
It worked fine when I ran this using the TryParse method on Int32.
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Greg Wilkerson" <gr***********@charter.net> wrote in message
news:6v********************************@4ax.com... 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
On Mon, 12 Dec 2005 12:41:43 -0500, "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote:
Greg,
It worked fine when I ran this using the TryParse method on Int32. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: john |
last post by:
Relatively new to C coding, so any help would greatly be appreciated.
I'm having problems try to return my string array from my parsing
function. When I do a printf I am getting the correct value...
|
by: Joachim |
last post by:
When I run double.TryParse("12.01234567890123456789", out value) I only get
12.0123456789012 as result. How can I get double.TryParse to translate more
than 13 decimals (if possible)?
|
by: MC |
last post by:
Let's say I want to validate something with TryParse but I don't need
to convert it. In C#, it seems I must provide that out parameter
regardless. In VB, I can pass Nothing. I'd like to be able...
|
by: John A Grandy |
last post by:
Primitives like Int32 provide a Parse() method , and TryParse() method --
which is very useful.
Enum provides a Parse() method, but not a TryParse() method.
Other than wrapping the...
|
by: bungle |
last post by:
Hi,
Would anyone be able to explain why I get a "Input string was not in a
correct format" on the following bit of code in C#??
public static int GENERIC_READ =...
|
by: Steffan A. Cline |
last post by:
When using this as indicated and trying to set it to accept multiple
formats, it bombs out with the error:
Overload resolution failed because no accessible 'TryParse' accepts this
number of...
|
by: dehranph |
last post by:
I have this code that always return zero whenever i passed 1,000,00 in
a da-DK culture or en-US culture. It works with amount less that 1000
like 99,99. but always returns 0 when greater than or...
|
by: nautonnier |
last post by:
Hello All,
I'm validating a textbox to make sure it contains only a whole number
so I'm using Int32.TryParse. It works fine when I test it on a local
winform app. However, when I transfer the...
|
by: steven |
last post by:
Hi
Anybody know why there's no TryParse method for a string type? I can
do the following when trying to convert an object to int:
object oTest = 1;
int iValue;
int.TryParse(oTest, iValue);
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |