Blue Theme Orange Theme Green Theme Red Theme
 
Nevron Gauge for SharePoint
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

How To Convert A Number Into String Format

 by Ghanashyam Nayak on Nov 17, 2011

Here I Am Showing You A Code Which Will Convert A Given Number Into String Format Like Ten For 10, Twenty Five For 25, etc....
Download Files: NumberToStringFormat.zip
Comments: 0 Views: 1224 Printable Version 

Here I Am Showing You A Code Which Will Convert A Given Number Into String Format Like Ten For 10, Twenty Five For 25, etc....

Here I have created one function which will accept the user's given number as input parameter to the function. after that the function will perform the operation on that user's given number & convert it into string format.

Here is the code:
 

public static string NumberToString(int num)

  {

            if (num < 0)

                return "Minus " + NumberToString(-num);

            else if (num == 0)

                return "";

            else if (num <= 19)

                return new string[] {"One", "Two", "Thiree", "Four", "Five",

                                    "Six", "Seven", "Eigh", "Nine", "Ten",

                                    "Eleven", "Twelve", "Thirteen", "Fourteen",

                                    "Fifteen", "Sixteen", "Seventeen", "Eighteen",

                                    "Nineteen"}[num - 1] + " ";

            else if (num <= 99)

                return new string[] {"Twenty", "Thirty", "Forty", "Fifty", "Sixty","Seventy",

                        "Eighty", "Ninety"}[num / 10 - 2] + " " + NumberToString(num %10);

            else if (num <= 199)

                return "One Hundred " + NumberToString(num % 100);

            else if (num <= 999)

                return NumberToString(num / 100) + "Hundreds " + NumberToString(num% 100);

            else if (num <= 1999)

                return "One Thousand " + NumberToString(num % 1000);

            else if (num <= 999999)

                return NumberToString(num / 1000) + "Thousands " + NumberToStrin(num % 1000);

            else if (num <= 1999999)

                return "One Million " + NumberToString(num % 1000000);

            else if (num <= 999999999)

                return NumberToString(num / 1000000) + "Millions " + NumberToStrin(num % 1000000);

            else if (num <= 1999999999)

                return "One Billion " + NumberToString(num % 1000000000);

            else

                return NumberToString(num / 1000000000) + "Billions " + NumberToStrin(num % 1000000000);

    }

        private void button1_Click(object sender, EventArgs e)

        {

            string tmp;

            tmp = NumberToString(226);

            MessageBox.Show(tmp);

        }

The given function will return the string that's why you have to store the return value in some temporary string variable & you can display that to the user.v

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 
Comments not available.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor

 Blogger's Profile
Age: Not Available
Location:
Title: Student
Joined: Mar 11, 2011
Education: Masters Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.