I wrote a code for which
if 23E+20 is the input then output should be 230000000(20 zeros)
if 4.456E-14 is the input then 4.456000(14 zeros) should be the output
But its not working properly.
Please let me know where I did error.
Thank You.
using System;
class test
{
public static void Main()
{
Console.WriteLine("Enter double");
String ext =Console.ReadLine();
if(ext.IndexOf("E")!=-1)
{
int i=ext.IndexOf("E");
ext = ext.Substring(0, i);
for (int j = 0; j < int.Parse(ext.Substring(i + 1, ext.Length - (i + 1))); j++)
ext = ext + "0";
Console.WriteLine(ext);
}
}
Console.ReadKey();
}
}
When you substring ext in
ext = ext.Substring(0,i)
you are assigning ext = “4.456” and cutting away the e-part
when you do ext.Length – (i + 1) in the for loop you get a negative index
Try this instead