I'd like to format a Number, say, a float or a double, as a String inthe Format 999,999.99 and then display it.How can this be done ?
yes it cain it is double.tostring("the number")
Thanks for the reply.toString returns a default String. As far as I am aware, it does notprovide the flexibility to format this String in a programmer-specifiable manner.I really wanted to ask if there is a ready-made method to format anumber in a programmer-specifiable manner.
You can use the java.text package. It provides a variety of formats.
You should use the class java.text.DecimalFormat. I haven't used itmyself, so I can't help you much more, but this is probably the classyou need.
Here is a quick example:import java.text.DecimalFormat;class Format{public static void main(String[] args){String input = "12345678.2";DecimalFormat formatter = newDecimalFormat("#,###,###.00");String s = formatter.format(Double.parseDouble(input) );System.out.println( s );}}
the following link have the needede informationjava.sun.com/.../decimalFormat.html
u can try this...newjava.text.DecimalFormat("###,###.##").format(1234567890.123d)