开发者

How to round a sum for the swiss currency (francs)

开发者 https://www.devze.com 2022-12-17 22:27 出处:网络
here in switzer开发者_C百科land our currency is francs and the smallest coin is 5 centimes which is 0.05 francs. what is the best way to round amounts to be payable with our money using the programmin

here in switzer开发者_C百科land our currency is francs and the smallest coin is 5 centimes which is 0.05 francs. what is the best way to round amounts to be payable with our money using the programming language ABAP in a SAP R/3 system?

examples:

" 4.48 should round to 4.50
" 2746.24 should round to 2746.25


REPORT  zwvtest.

PARAMETERS: p_in  TYPE dec11_4,
            p_out TYPE dec11_4.

DATA: l_fraction    TYPE dec11_4,
      l_upper       TYPE dec11_4,
      l_delta_upper TYPE dec11_4,
      l_lower       TYPE dec11_4,
      l_delta_lower TYPE dec11_4.

AT SELECTION-SCREEN.
  l_fraction = FRAC( p_in * 10 ) / 10.
  l_upper = CEIL( l_fraction * 20 ) / 20.
  l_delta_upper = l_upper - l_fraction.
  l_lower = FLOOR( l_fraction * 20 ) / 20.
  l_delta_lower = l_fraction - l_lower.
  IF l_delta_lower < l_delta_upper.
    p_out = p_in - l_delta_lower.
  ELSE.
    p_out = p_in + l_delta_upper.
  ENDIF.

...if you want it rounded up or down depending on what's the closest value.


it looks like there IS a standard module:

DATA: result TYPE dec11_4.

CALL FUNCTION 'FIMA_NUMERICAL_VALUE_ROUND'    
  EXPORTING
    i_rtype     = space
    i_runit     = '0.05'
    i_value     = '4.48'
  IMPORTING
    e_value_rnd = result.

i_rtype controls whether it is rounded up (+), down (-) or commercial (space).

0

精彩评论

暂无评论...
验证码 换一张
取 消