Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2008

Tip: Looking for answers? Try searching our database.

Bug in Double.MinValue?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrik Kruse - 25 Jan 2008 08:54 GMT
This line exectues with an exception:

double d = double.Parse(double.MinValue.ToString());

The error message is "Value was either too large or too small for a Double".

Is this an error in the framwork?

/Patrik
Jon Skeet [C# MVP] - 25 Jan 2008 09:08 GMT
On Jan 25, 8:54 am, Patrik Kruse
<PatrikKr...@discussions.microsoft.com> wrote:
> This line exectues with an exception:
>
[quoted text clipped - 3 lines]
>
> Is this an error in the framwork?

Not quite - it's a bug in how you're formatting it. If you call plain
ToString() there's no guarantee that that value can be parsed, or that
it will be parsed to exactly the same value. The "r" format string
(roundtrip) makes that guarantee, so the following works:

double d = double.Parse(double.MinValue.ToString("r"));

I agree it's counterintuitive, but look at the two strings produced
and you'll see why it happens.

Jon

Jon
Patrik Kruse - 25 Jan 2008 09:30 GMT
Thanks Jon,

it is really not intuitive, and I get the value from a SOAP request so the
generation of it is out of my control.

I guess I must hardcode the min value string to be able to recognise the
value received as MinValue (used as null) then... :(

/Patrik

> On Jan 25, 8:54 am, Patrik Kruse
> <PatrikKr...@discussions.microsoft.com> wrote:
[quoted text clipped - 19 lines]
>
> Jon

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.