This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Casting problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Casting problem" Watch "Casting problem" New topic
Author

Casting problem

Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
hi ranchers !
i have a problem in casting the double data type into the string type.
i have write a code as
double i=100*Math.random();
String a=i.toString();
but it is throwing an error .please give anybody give the suggestion that how i can convert a random number into a string type.
thanks in Advance
Amar Deep Chaudhary


"A thinking mind never dies"
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You can't call a method on a primitive.

If you look at the String API, you will find an overloaded method called valueOf that will let you convert any type to a String.
Maurizio Nagni
Ranch Hand

Joined: May 29, 2004
Posts: 75
Moreover if you want a more strict control over type you can use also
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Casting problem
 
Similar Threads
converting float to double
Help with parameters for JOptionPane.showMessageDialog
cast
The method setAlt(String) in the type BaseHandlerTag is not applicable for the arguments (int)
converting double into integer