Formats a number using the general number format with exactly three decimal places: - Java Language Basics

Java examples for Language Basics:Number Format

Description

Formats a number using the general number format with exactly three decimal places:

Demo Code

import java.text.NumberFormat;

public class Main {
  public static void main(String[] args) {
    double x = 12345.6789;
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMinimumFractionDigits(3);/*from  ww w .j a va2s .c  om*/
    nf.setMaximumFractionDigits(3);
    System.out.println(nf.format(x));

  }

}

Related Tutorials