Skip to Content
author's profile photo Former Member
Former Member

Rounding Off a Numeric Value

Hi Friends,

I want to round of a value

example :

6521.45 to 6521.00 and Round off is 0.45

if

6521.55 to 6522.00 and round off is 0.45

i want the vale and round of figure

is there any FM Avaliable or any Code should we write

Thanks and Regards

Kumar M

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Feb 07, 2008 at 12:26 PM

    Hi,

    declare result as type p with req no of decimal places.

    it automatically rounds off.

    Jayant Sahu

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 07, 2008 at 12:28 PM

    HI,

    Check 'ROUND' FM.

    data: nu(10) type p decimals 4.
    data: nu1(5) type p decimals 2.
    
    nu = '4.017'.
    CALL FUNCTION 'ROUND'
    EXPORTING
    DECIMALS = 2
    INPUT = nu
    
        * SIGN = ' '
    
    IMPORTING
    OUTPUT = nu1
    
        * EXCEPTIONS
        * NPUT_INVALID = 1
        * OVERFLOW = 2
    
    *TYPE_INVALID = 3
    
        * OTHERS = 4
     

    Regards,

    Santosh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 07, 2008 at 12:29 PM

    first use ceil or floor on the numeric value ...

    then subtract the result from the original ...

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 07, 2008 at 12:29 PM

    Hi,

    Declare that Final variable as packed decimal(P)

    data: total type p.

    regards,

    ravi shankar reddy

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 07, 2008 at 12:33 PM

    hi,

    HR_ROUND_NUMBER – Rounds a number according to rules

    ROUND – Rounds value to a number of decimal places

    ROUND_AMOUNT – Rounding based on company and currency

    UNIT_CONVERSION_SIMPLE – Converts measurement unit values and rounds

    Hope this is helpful, Do reward.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 07, 2008 at 12:49 PM

    Hi,

    DATA X TYPE P DECIMALS 2.

    DATA N TYPE P DECIMALS 2.

    DATA M TYPE P DECIMALS 2 VALUE '6521.55 '.

    N = FRAC( M ).

    if ( N > 0.5 )

    X = floor( M).

    else

    X = ceil( M ).

    endif

    write:/ X. -> value

    write:/ N. -> rounded figure

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 07, 2008 at 01:50 PM

    HI,

    you can use CEIL or FLOOR statements,

    Else assign the value to a variable of type i, Integer then it will be automatically rounded of without decimals.

    KindRegards,

    khader.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 25, 2008 at 06:59 AM

    data: a type p value '100.235' decimals 3,

    b type p decimals 2.

    CALL FUNCTION 'ROUND'

    EXPORTING

    DECIMALS = '3'

    input = a

    • SIGN = ' '

    IMPORTING

    OUTPUT = b

    • EXCEPTIONS

    • INPUT_INVALID = 1

    • OVERFLOW = 2

    • TYPE_INVALID = 3

    • OTHERS = 4

    .

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    write: a , b.

    ans 100.235, 100.24

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.