How to Format Floating Point Number in Java

public DecimalFormat(String pattern)

Creates a DecimalFormat using the given pattern and the symbols for the default locale. This is a convenient way to obtain a DecimalFormat when internationalization is not the main concern.

To obtain standard formats for a given locale, use the factory methods on NumberFormat such as getNumberInstance. These factories will return the most appropriate sub-class of NumberFormat for a given locale.


String fmt = "0.00#";
DecimalFormat df = new DecimalFormat(fmt);
double q = 10.0/4.0;
String str = df.format(q);
System.out.println("q = "+str);

Related Posts:

One Responses

radhakrishnavangara July 26, 2008 at 5:48 am

Can you please explain me. how to integrate php mysql and tomcat

Comments are closed.