javadecimalformatibm-jdk

DecimalFormat gives differfent result in Oracle Java 1.7 and IBM java 1.6


lets have a simple test code:

public static void main(String ... arg)
{
    double d = 4000.0;
    DecimalFormat df = new DecimalFormat("#,###.##");
    System.out.println(df.format(d));
}

In Oracle/SUN java output is (with space):

4 000

But in IBM java i got:

4,000

My java:

java version "1.7.0_51" Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

IBM java:

java -version java version "1.6.0" Java(TM) SE Runtime Environment (build pap6460_26sr7ifix-20131203_01(SR7+IX90131+IV52621)) IBM J9 VM (build 2.6, JRE 1.6.0 AIX ppc64-64 Compressed References 20131011_170248 (JIT enabled, AOT enabled) J9VM - R26_Java626_SR7_20131011_1221_B170248 JIT - r11.b05_20131003_47443 GC - R26_Java626_SR7_20131011_1221_B170248_CMPRSS J9CL - 20131011_170248) JCL - 20131015_01

Anyone have idea why is this? Is it because 1.6/1.7 difference? Or maybe its locale problem, probably not.


Solution

  • Ok i found probably solution here no grouping separator char for DecimalFormat

    Its so simple :)

    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setGroupingSeparator(' ');
    DecimalFormat df = new DecimalFormat("#,###.##");
    df.setDecimalFormatSymbols(symbols);
    

    apparently ibm and oracle uses different default group separator. Dunno why