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.