Java Data Type How to - Add hardcoded string in number format








Question

We would like to know how to add hardcoded string in number format.

Answer

import java.text.DecimalFormat;
import java.text.Format;
//from  w  w  w .  j  a  v a 2 s .c  om
public class Main {
  public static void main(String[] argv) throws Exception {

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

The code above generates the following result.