This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
i know this is not the good solution for your problem. i think it will slove your problem String a=""+22/12.0;//take in a String System.out.println(new Float(a.substring(0,5))); //take the required value convert it to Float
Joined: Mar 22, 2005
Originally posted by chiru surya: ...
Don't do this. For formatted printing you can use System.out.printf, and for in-memory formatting you can use the java.text.NumberFormat class. Both have plenty of options for formatting the number.
Originally posted by chiru surya: String a=""+22/12.0;//take in a String
Never ever ever do that again. The 22/12.0 part will be converted to a string, then added to the empty string. From now on, just call String.valueOf(22/12.0) - the resulting string will be the same but there will be fewer objects created.