Changing Decimal Point into a Comma

Tony Marston - 30th December 2001

The standard format in UNIFACE for displaying numerical values with decimal places is to use a decimal point (or period), as in "12345.67", but in some countries the practice is to use a comma instead of a period, as in "12345,67".

The choice of a period or a comma is usually decided in the display format of the field layout definitions, and can be switched from one to the quite easily, as shown in the following table:-


However, to make the switch from period to comma (or back again) this change has to be made to the layout definitions of every relevant field, then compiled into every relevant form. The chosen format then becomes set in stone.

But what if you have a single piece of software that is used by some people who want decimal points and others who want decimal commas? How is it possible to decide the format at run time?

Unfortunately there is no language setting as there is for date formats. The solution lies in the rarely-used <FORMAT> trigger. This enables you to override the way in which a field's value is converted from its internal format to its external (displayed or printed) format. The following code uses a global variable to decide if any reformatting is necessary, but you can use whatever mechanism you like.

Put this code in the <FORMAT> trigger:-

if ($$decimal_is_comma)
   call EXAMINE_REPLACE($format, ".", ",")  ; change period to comma

This reformatting should be reversed using this code in the <DEFORMAT> trigger:-

if ($$decimal_is_comma)
   call EXAMINE_REPLACE($format, ",", ".")  ; change comma to period

The code for proc EXAMINE_REPLACE can be found in a previous tip of mine called 'How to replace text in a string'.

Tony Marston
30th December 2001