Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

Convert Number to String

In this section, we will learn how to convert numbers to String.

Convert Number to String

                         

In this section, we will learn how to convert numbers to String. The following program provides you the functionality to convert numbers to String.

Code Description:

In this program we have declared different type of  numbers like float, int, long etc as shown below. We have used "valueOf()" method here which is a method of String class. We use "String.valueOf()" for numeric conversions and "toString()" method to convert these numeric classes to String as shown in the code below.

Here is the code of the program:

class NumToStr {
  public static void main(String[] args) {
    int i    = 40;
    float f  = (float100.0;
    long l   = 3000000;
    String s = new String();

    s = String.valueOf(i);
    System.out.println ("int i = " + s);
    s = String.valueOf(f);
    System.out.println ("float f = " + s);
    s = String.valueOf(l);
    System.out.println ("long l = " + s);
    s = new Integer(i).toString();
    System.out.println ("int i = " + s);
    s = new Float(f).toString();
    System.out.println ("float f = " + s);
    s = new Long(l).toString();
    System.out.println ("long l = " + s);
  }
}

Output of the program:

C:\unique>javac NumToStr.java

C:\unique>java NumToStr
int i = 40
float f = 100.0
long l = 3000000
int i = 40
float f = 100.0
long l = 3000000

C:\unique>

Download this example.

                         

» View all related tutorials
Related Tags: c convert io help this program to learn ram ear e il section in converting m ps pro s is

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

I need the code to convert numeric to string.
ex: input from keybord 25 the output twenty five

Posted by didi on Thursday, 12.18.08 @ 21:40pm | #82941

How to convert numeric to string by using C++ programming in Borland C software

Posted by popo on Friday, 12.12.08 @ 06:17am | #82684

 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.