The # symbol shows a digit or nothing if no digit present : Format « Development Class « Java






The # symbol shows a digit or nothing if no digit present

   

import java.text.DecimalFormat;
import java.text.Format;

public class Main {
  public static void main(String[] argv) throws Exception {

    Format formatter = new DecimalFormat("##");
    String s = formatter.format(-1234.567);
    System.out.println(s);
    s = formatter.format(0);
    System.out.println(s);
  }
}

   
    
    
  








Related examples in the same category

1.String Align Demo: extends FormatString Align Demo: extends Format
2.Format SizeFormat Size
3.Get Percent Value
4.A format for String objects that is easier to persist
5.Int format and conversion
6.Make custom Input Text Formatter in Java