| Author |
Converting Integers / Float/ Double etc to strings
|
Tim Dee
Greenhorn
Joined: May 07, 2005
Posts: 22
|
|
I know how to convert a string to Float / int etc But how do I go in the other direction and convert a integer to a string? Cheers
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24041
|
|
There are a number of ways to do it. I like to use the bunch of static "valueOf" methods in the String class: int anInt = 3; String intAsString = String.valueOf(anInt);
|
[Jess in Action][AskingGoodQuestions]
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
There are a number of different ways to do it. Check out the API documentation of class java.text.DecimalFormat and of the method String.format(...). With those, you can specify exactly with which format you want the numbers to be converted to strings. You can also use the static toString(...) methods of the wrapper classes, but those won't allow you to specify the format. Or even a trick like this, which will automatically call the toString(...) of the wrapper classes behind the scenes.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Converting Integers / Float/ Double etc to strings
|
|
|