Format decimal point with comma as decimal separator and without thousand separator

I have a requirement to format a decimal number with a semicolon as a decimal separator and without a thousand separator (neither a dot nor a space).

I would not be myself if I did not want to do this as one liner, but I could not find such a solution.

What I have now is a workaround.

DATA: l_value TYPE p LENGTH 9 DECIMALS 2 VALUE '-3450354.25'.

DATA(l_formatted_value) = |{ l_value SIGN = LEFTSPACE COUNTRY = 'DE ' }|.
REPLACE ALL OCCURENCES OF '.' IN l_formatted_value WITH ''.
WRITE: l_formatted_value.

I tried to do this with a parameter NUMBER = RAW, but then I didn't seem to find an easy way to specify the decimal separator as a comma.

DATA(l_formatted_value) = |{ l_value SIGN = LEFTSPACE NUMBER = RAW }|.
REPLACE '.' IN l_formatted_value WITH ','.

How can I achieve this as one liner? I would also like to avoid using WRITE.

+4
source share
1 answer

, , , . , . , , . 12.50 12,5.

|{ trunc( l_value ) },{  trunc( frac( l_value ) * 100  ) }|

, .

+4

Source: https://habr.com/ru/post/1614346/


All Articles