How to Format Floating Point Number in Java

July 26th, 2008One Comment

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.

Eg.

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:

Tagged : ,

One Responses

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