DecimalFormat(abc#) in Java



DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers.

Let us set DecimalFormat(abc#) first −

Format f = new DecimalFormat("'abc'#");

Now, we will format a number and display the result in a string using the format() method −

String res = f.format(-3968.7878);

Since, we have used both Format and DecimalFormat class in Java, therefore importing the following packages in a must −

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

The following the complete example −

Example

 Live Demo

import java.text.DecimalFormat;
import java.text.Format;
public class Demo {
   public static void main(String[] argv) throws Exception {
      Format f = new DecimalFormat("'abc'#");
      String res = f.format(-3968.7878);
      System.out.println(res);
   }
}

Output

-abc3969
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements