SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Округление до двух знаков после запятой



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
Лазарев
Участник
Участник



Joined: 26 Sep 2007
Posts: 22

PostPosted: Fri Nov 23, 2007 10:15 am    Post subject: Округление до двух знаков после запятой Reply with quote

Доброе утро!
Какой функцией сделать округление до двух знаков после запятой? Желательно с примером. Спасибо.
Back to top
View user's profile Send private message
july7
Старший специалист
Старший специалист



Joined: 10 Oct 2007
Posts: 109
Location: Киров

PostPosted: Fri Nov 23, 2007 10:40 am    Post subject: Reply with quote

Используйте ФМ ROUND - Rounding to spec. no. of dec. place (round up, round down, comm. rounding)
This function module rounds the value INPUT to ANDEC decimal places. The parameter SIGN determines whether rounding is down ('-'), up ('+') or commercial ('X').
If SIGN = SPACE, there is no rounding (OUTPUT = INPUT).

Code:
*The value VALUE is to be rounded up to the nearest hundred.
DATA: VALUE TYPE F,
ROUND_VALUE TYPE F.
...
CALL FUNCTION 'ROUND'
EXPORTING
DECIMALS = 2-
INPUT = VALUE
SIGN = '+'
IMPORTING
OUTPUT = ROUND_VALUE
EXCEPTIONS
INPUT_INVALD = 01
OVERFLOW = 02
TYPE_INVALID = 03.


Note
The result of floating point rounding calculations can be incorrect in certain cases because of rounding errors.
If INPUT is a field of type P, internal calculatons similarly use packed numbers. This is expensive, but more accurate. If the calculation accuracy is very important, INPUT should thus be a field of type P.
Parameters
OUTPUT
DECIMALS
Negative values are also allowed here:
For positive values count to the right from the decimal point, for negative values, to the left.
E.g.: 1234,1234 rounded to -2 decimal places equals 1200
1234,1234 rounded to 2 decimal places equals 1234,12
INPUT
SIGN
SPACE : no rounding (input = output)
'+' : round up
'-' : round down
'X' : commercial rounding
Back to top
View user's profile Send private message
Lord
Профессионал
Профессионал



Joined: 10 Sep 2007
Posts: 168

PostPosted: Fri Nov 23, 2007 11:39 pm    Post subject: Reply with quote

Еще варинт с использованием встроенных функций

Code:

*rounding to 2 decimals
   DATA: l_frac       TYPE vbrp-netwr,
             l_uom      TYPE vbrp-netwr.

      l_frac = frac( l_uom ).
      IF l_frac > '0.5'.
        l_uom = ceil( l_uom ).
      ELSE.
        l_uom = floor( l_uom ).
      ENDIF.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.