converting double to string

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 6
Dark_Omen Dark_Omen is offline Offline
Posting Pro

converting double to string

 
0
  #1
Dec 8th, 2005
Is there a way to convert a double to string. I tried to do it like this x.toString() and it didnt work as well as implicitly converting it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 216
Reputation: hooknc is an unknown quantity at this point 
Solved Threads: 8
hooknc hooknc is offline Offline
Posting Whiz in Training

Re: converting double to string

 
0
  #2
Dec 8th, 2005
Originally Posted by Dark_Omen
Is there a way to convert a double to string. I tried to do it like this x.toString() and it didnt work as well as implicitly converting it.
double is a primative not a Class and you cannot call methods on it like a Class/Object.

There are several ways to convert a double to a String...
  1. double value = 1.0;
  2.  
  3. // This is ok.
  4. String firstDouble = value + "";
  5.  
  6. // This is better.
  7. String secondDouble = Double.toString(value);

There are other ways, but these two ways will work fine.

Regards,

Nate
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 14112 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC