C# trouble converting from string to double.
public static String[] ParsePowers(String[] InString)
{
String[] OutString = InString;
char[] TestMe;
int[] counter = new int[10];
counter[0] = 0;
while (counter[0] < (InString.Length - 1))
{
TestMe = OutString[(counter[0] + 1)].ToCharArray();
Console.WriteLine("{0}", TestMe[0]);
if (TestMe[0] == '^')
{
OutString = ReString(OutString, counter[0], (counter[0] + 2), DoPower(OutString[counter[0]], OutString[(counter[0] + 2)]));
}
counter[0]++;
}
return OutString;
}
public static string DoPower(String One, String Two)
{
double DOne = System.Convert.ToDouble(One);
double DTwo = System.Convert.ToDouble(Two);
double Out = DOne;
int counter = 0;
while (counter < DTwo)
{
Out = Out * DOne;
counter++;
}
String OutS = Out.ToString();
return OutS;
}
with this tester:
public class Tester
{
static void Main()
{
// public static String[] ParseOne(String InString)
String UHG = "2.2^2.2";
String[] Blug;
Blug = StringMath.ParseOne(UHG);
Blug = StringMath.ParsePowers(Blug);
int counter = 0;
while (counter < Blug.Length)
{
Console.WriteLine("{0}", Blug[counter]);
counter++;
}
}
}
note: ParseOne output the string 2.2^2.2 to a strign array with 2.2 in index 0, ^ in index 1, and 2.2 in index 2.
error:
Uncaught exception: System.FormatException: The supplied value did not have the correct format
at System.Private.NumberParser.ParseDouble(String, NumberStyles, NumberFormatInfo) in ./System/Private/NumberParser.cs:1219
at System.Double.Parse(String, NumberStyles, IFormatProvider) in ./System/Double.cs:127
at System.Double.Parse(String) in ./System/Double.cs:149
at System.Convert.ToDouble(String) in ./System/Convert.cs:2420
at StringMathNS.StringMath.DoPower(String, String)
at StringMathNS.StringMath.ParsePowers(String[])
at Tester.Main()
I tried a writeline and found the bug occurs in the parse to double section (duh, but ti double confirmed it)
what woudl the problem likely be? the ParseOne function works fine.
Last edited by exodist; 02-23-2004 at 02:38 PM.
|