Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a bit stumped

 
joew weakers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there. How does one cast a Float object to a String object or is that possible at all. I have a method which takes a string as argument and logs the string to a file. My program returns the scale of a map in a float format. I need to take this float value and output it to my logfile but I need to convert it to a string format first of all. You cannot cast a float to a string according to my compiler which seems fair enough. So how can I overcome this little burden. Thanks Joe
 
Arulkumar Gopalan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does one cast a Float object to a String object or is that possible at all.

you can use floatObject.toString() method to convert it as string.
 
Arulkumar Gopalan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static methods are also available.. check out the following URL to know what are all the methods available.
Java API
 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, you can use implicit conversion with String concatenation, e.g.:
 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to be clear about my previous post, that only works for primitives, i.e. float not Float, but you can get a float from a Float by calling the method floatValue() on it.
So float on...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic