Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

        }
        decimal ParseDecimal(string number)
        {
            if (number.Equals("0E+3",StringComparison.OrdinalIgnoreCase))
            {
                return 0;
            }

            return decimal.Parse(number, System.Globalization.NumberStyles.Any);
           Console.WriteLine(number);
        }
    }
}
Posted
Comments
[no name] 4-Jul-12 6:50am    
Yes, yes very nice... and?

You call
Console.WriteLine(number);
after you return value from method.So it will never be called.

Try it like that:

C#
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
             Program p = new Program();
             decimal result = p.ParseDecimal("2.5");
             //you can return void if you will not use result
        }
        decimal ParseDecimal(string number)
        {
            if (number.Equals("0E+3",StringComparison.OrdinalIgnoreCase))
            {
                return 0;
            }
            Console.WriteLine(number);
            return decimal.Parse(number, System.Globalization.NumberStyles.Any);         
        }
    }
}
 
Share this answer
 
v3
Comments
nagumammu 4-Jul-12 7:15am    
im tried when run the progrm in cmd prmpt csc Program.cs it is not showing errors, when run program Program.cs ,it will not showing any result.
sderen 4-Jul-12 7:19am    
It is showing the result, but probably you are not seeing it because of console window closes.Try adding
Console.ReadLine();
after calling ParseDecimal method.
Raje_ 4-Jul-12 7:22am    
you need to write Console.WriteLine() in Main function like given below:
decimal dec = ParseDecimal("2.78");
Console.WriteLine(dec);
and run it (ctrl+f5);
Unreachable code detected

Because of the last line .The last line of the function never execute due to the return line written above the
Console.WriteLine(number);


Remove the last line or write the line above the return statement.

and also consider answer 1 Please write something(call the function) in the main function.
 
Share this answer
 
try this code:-
C#
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
           decimal dec = ParseDecimal("2.78");
           Console.WriteLine(dec);
        }
       static decimal ParseDecimal(string number)
        {
         //#pragma warning disable
            if (number.Equals("0E+3", StringComparison.OrdinalIgnoreCase))
            {
                return 0;
            }
           return decimal.Parse(number, System.Globalization.NumberStyles.Any);
        }
    }
}
 
Share this answer
 
Comments
nagumammu 4-Jul-12 7:21am    
Now also same error,not getting any result,please help me
Raje_ 4-Jul-12 7:29am    
copy the given code and run it, for running press (ctrl+f5), and let me know what error is coming.
nagumammu 4-Jul-12 7:52am    
like 2.78 press enter to continue.... not getting any error,
The purpose of this program is to the value 2.94676283374429E-08,i want the value in numbers not in E.so i want convert this value to numbers.
nagumammu 4-Jul-12 7:53am    
no error,but not showing any value when run the program.how to get the value
Raje_ 4-Jul-12 11:42am    
in Main() function write following code:
decimal dec = ParseDecimal("2.94676283374429E-08");
Console.WriteLine(dec);
you probably missing the Console.WriteLine(dec); line. this line is responsible for displaying output in command prompt.
yes,but now also Im not getting answer?
 
Share this answer
 
Comments
bhagirathimfs 4-Jul-12 7:07am    
Please don't post an answer.
In every answer below a button is there to ask question i.e."Have a Question or Comment" Click on that button and write the question want to ask the person..
bhagirathimfs 4-Jul-12 7:07am    
What are you not getting ??
Again you are getting the same error??
nagumammu 4-Jul-12 7:12am    
but not working,program compiled but answer is not getting the command prompt window is closed when run the program

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900