Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert int ,double to string

 
Vishal Dharod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I convert int or double to a string.
thanks
 
Joe Pluta
Ranch Hand
Posts: 1376
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Short answer(s):

Long answer: There's a very neat page by a guy name Roedy Green that shows how to convert just about any Java type to any other Java type. You have to have a pretty recent browser (IE6 or the latest Mozilla), but his applet will show you everything you need to know:
http://mindprod.com/converter.html
Joe
 
Vishal Dharod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THanks a lot Joe
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the lazy...
int x;
...
String s = "" + x;
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dirk, I think
String s = String.valueOf(x);
is more for the lazy one - it's as easy to remember and much more easy to read and understand. And I am likely to have to read it much more often than to write it...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic