MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class MainClass {

    public static void main(String[] argv) {
        double d = 1234567.89;
        double n = -1234567.89;

        String pattern = "#,###.##;(#,###.##)";

        NumberFormat nf = NumberFormat.getInstance();
        if (nf instanceof DecimalFormat) {
            DecimalFormat df = (DecimalFormat) nf;
            df.applyPattern(pattern);
            System.out.println(df.format(d));
            System.out.println(df.format(n));
        }

    }
}