Java DecimalFormat format decimal and round to three digit after decimal point

Description

Java DecimalFormat format decimal and round to three digit after decimal point

import java.text.DecimalFormat;

public class Main {
  public static void main(String[] args) throws Exception {
    DecimalFormat myFormatter = new DecimalFormat("000000.000");
    String output = myFormatter.format(123456.78999999);
    System.out.println(output);/*from w  ww.ja  va 2 s  .  co  m*/
  }
}



PreviousNext

Related