.NET Default Numeric String Formatting not Reflexive?

January 28th, 2008

Does the following look like it should throw an exception?

Double.Parse(Double.MaxValue.ToString())

I didn’t think so either, but it turns out I was wrong. Double.MaxValue.ToString() yields 1.79769313486232E+308 when the actual maximum value of a Double is 1.7976931348623157E+308. Ok, we’ll shave off a few digits of precision with the default formatting and round up. Sure…Turns out you need to use the “roundtrip” option…sigh. Thanks to this reference.

Double.Parse(Double.MaxValue.ToString("R"))

Entry Filed under: .NET

1 Comment Add your own

  • 1. Nathaniel David  |  July 27th, 2008 at 8:31 pm

    Thank you!

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

January 2008
M T W T F S S
« Nov   Mar »
 123456
78910111213
14151617181920
21222324252627
28293031  

Most Recent Posts