Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I convert an int to a string.

Status
Not open for further replies.

martindavey

Programmer
Jan 2, 2000
122
GB
int myNum = 100;
I want to use g.drawString( myNum, x, y );
 
you could say

String myString = new String(" " + myNum + " ");
myString.trim();

The blank space is needed to make the argument to the constructor valid (not sure if you need spaces in front and behind, one may suffice). And the trim method just gets rid of them.

Or you could say

Integer myInt = new Integer(myNumber);

and use the Integer method toString() to return a String object of teh number every time you need it.

myInt.toString();
bruce08.gif
 
How about:
Code:
int myNum = 100;
g.drawString(String.valueOf(myNum),x,y);
Wushutwist
 
A little correction to pipk's post. All you need is:-

g.drawString( ""+myNum, x, y );

No need for space and trimming :)

Leon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top