Change the decimal separator to "." in Java

Description

The following code shows how to change the decimal separator to ".".

Example


/* w  ww. jav a  2s .co  m*/
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

public class Main {
  public static void main(String args[]) {
    double d = 123456.7890;
    DecimalFormat df = new DecimalFormat("#####0.00");
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

    dfs.setDecimalSeparator('.');
    df.setDecimalFormatSymbols(dfs);
    System.out.println(df.format(d));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Data Format »




Java Formatter
Java Number Formatter