Created On:  28 March 2011

Problem:

How can I change the decimal fraction separator character from a decimal point to a comma for display purposes?

Resolution:

Following are 2 ways of setting your program to display a comma as the fraction separator character for display purposes. But they are slightly different.

One way is to set DECIMAL-POINT IS COMMA in the SPECIAL-NAMES paragraph.

Eg:

Special-Names.

        Decimal-Point is Comma.     

This can be used where code already has the comma as the decimal fraction separator and the decimal point as the thousands separator.

For example, take the following code:

01  Display-Field                PIC ZZ.ZZZ.ZZ9,99.

Move 1234,56 To Display-Field

Display Display-Field

Without DECIMAL-POINT IS COMMA in Special-Names this code would not compile.

But with DECIMAL-POINT IS COMMA in Special-Names this would compile and run with the output as follows:

1.234,56

So in this instance DECIMAL-POINT IS COMMA tells the compiler that the code has been written with the comma and full stop reversed in numeric display fields. It doesn’t change the code, it just allows the fields to be specified in that format.

If we reversed that and compiled the following (what we’d mostly consider as normal) code with DECIMAL-POINT IS COMMA in Special-Names:

01  Display-Field                PIC ZZ,ZZZ,ZZ9.99.

Move 1234.56 To Display-Field

we’d get a compiler error: PICTURE string has illegal precedence or illegal character

So in this instance DECIMAL-POINT IS COMMA allows code in that format to be used.

Another thing you can do is use the NLS compiler directive. The difference here is that using this allows the decimal point to be specified by the system locale (character set) at the time the program is run. But, if the NLS compiler directive is set the LANG environment variable should be set to the correct character set.

For example,  let’s take the following code:

$SET NLS

01  Display-Field                PIC ZZ,ZZZ,ZZ9.99.

Move 1234.56 To Display-Field

Display-Field

With the $LANG=it_IT environment variable set (i.e. for Italian) you’d get the following result:

1234,56

But with $LANG=en_US you’d get:

1,234.56

Therefore if you use the NLS compiler directive, you must set $LANG to a valid value.

Under Unix/Linux, the command ‘locale –a’ displays the valid values of $LANG for your operating system.