Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

this should be simple...

Status
Not open for further replies.

bluepixie

Programmer
Jul 31, 2003
34
US
Hi I need to remove the .0 from a double. But I don't want to cast to int in all cases because I could have something like 67.002 where I don't want to truncate any meaningful data.
thanks!
 
There are probably far more mathemeatical and sophisticated ways of doing this, but I can't think of any right now !

Code:
double d = 0.0d;

String ds = d +"";
String[] dss = ds.split(".");

if (dss[1].equals("0")) {

  // just a n.0 number
} else {
   // has some other format like n.013581
}
 
Thanks,
I acually found some number formatting code that I can re-use in our app but it actually turns the double into a String. So now when I convert back to double, I get the trailing .0 again. Is there a way to convert back to double without adding on the trailing zero and not truncate any meaningful data?
thanks again
 
No, because a double, by definition has a decimal place !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top