When I use Double.toString(), it converts the value 24 to 24.0. I want to display the value as it is(ie.. only 24).. But when I have a number like 24.5, then it should be displayed as 24.5 How can I do this functionality by using sigle function? That means when I pass 24/24.5(Numeric value) to a function, then it should return 24/24.5(String). It shouldn't return 24.0/24.5(String).
You could try altering your formatting String Work backwards from Now, try and alter the string you use for your formatting. Now, try and work back to the bit you have afterwards, the "%.1" bit. You can alter that depending on whether number % 1 == 0 or not.
This won't work on Java 1.4.2 or older.
Makesh Kumar Ramakrishnan
Joined: Jan 07, 2006
Thanks Marc. I used DecimalFormat and It works fine. Thats what exactly wanted. Thanks for your help.