Parsing a numberical string with a decimal into a

Results 1 to 2 of 2

Thread: Parsing a numberical string with a decimal into a

  1. #1
    Join Date
    Dec 1969

    Default Parsing a numberical string with a decimal into a

    I am simply trying to convert a string variable with the value of "0.0" to a double variable using C#.<BR><BR>If I use the parsing method like this:<BR><BR> double myDouble;<BR> myDouble = Double.Parse("0.0");<BR><BR>Then it will parse fine. However, when I do this:<BR><BR>string myString;<BR>double myDouble;<BR><BR>myString = "0.0";<BR>double = Double.Parse(myString);<BR><BR>I get this error:<BR><BR>System.FormatException: Input string was not in a correct format. <BR>at System.Number.ParseDouble(String s, NumberStyles style, NumberFormatInfo info) <BR>at System.Double.Parse(String s, NumberStyles style, IFormatProvider provider)<BR>at System.Double.Parse(String s, NumberStyles style)<BR>at System.Double.Parse(String s)<BR><BR><BR>I have tried something like this, but I got no where:<BR><BR>string preDec;<BR>double moMO;<BR><BR>NumberFormatInfo myFormat = new NumberFormatInfo();<BR>myFormat.CurrencyDecimalDig its = 2;<BR><BR>preDec = "1.5";<BR>moMO = Double.Parse<BR>(preDec,NumberStyles.AllowDecimalP oint,myFormat);

  2. #2
    Join Date
    Dec 1969

    Default RE: Parsing a numberical string with a decimal int

    This code:<BR>[code language="C#"]<BR>string myString;<BR>double myDouble;<BR><BR>myString = "0.0";<BR>double = Double.Parse(myString);<BR>[/code]<BR>doesn&#039;t make any sense.<BR><BR>It should be this:<BR>[code language="C#"]<BR>string myString;<BR>double myDouble;<BR><BR>myString = "0.0";<BR>myDouble = Double.Parse(myString);<BR>[/code]<BR>which works just fine.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts