In a terminal program I'm writing values are inputted and stored in a pair of arrays. At one point in the program I need to print them back out.

My problem is that if I input 1.10, Java gives me 1.1. I really need it to print the zero even if its in the least significant place.

Searching around on Google suggested using DecimalFormat, but I can't get that working. Any ideas?


NumberFormat is an abstract class; use its static factory method to get your choice of number formatter.

public class MainTest {
   public static void main(String args[]) throws Exception {
      // Get a number formatter for the default locale
      NumberFormat nf = NumberFormat.getNumberInstance();
      // Get a number formatter for a different locale e.g. french
      nf = NumberFormat.getNumberInstance(Locale.FRENCH);
This question has already been answered. Start a new discussion instead.