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

Issue with packed numbers

I'm using 2 packed numbers. And fixed point arthimetic is not checked in my program and i don't want to check that. While dividing these two numbers the decimal portion is getting truncated.

How to resolve this problem?

I've tried moving the number to a character variable but this is of no use if the user follows the decimal notation as ',' then the division throws dump.

Please help me.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 05, 2006 at 09:44 AM

    i think for division or multiplication u have to check.

    fixed point arthimetic

    or u have to multiply by content to display right position.

    it means if it truncate 2 decimal place multiply by 100...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 05, 2006 at 09:46 AM

    soppuse num3 = num1/num2..

    take num1,num2,num3 as same type..

    then it works fine...

    if it is not working pls post ur code part how u assiened and how u r calculating...then we resolve it..ok

    Ramesh.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      parameters: p_1 type p decimals 2,

      p_2 type p decimals 2.

      data p_3 type p decimals 2.

      p_3 = p_2 / p_1 .

      Enter these values for p_1 and p_2 as my user settings permits ',' as decimal.

      p_1 = '30,50'.

      p_2 = '71,00'.

      i should get p_3 value as 0,50 without using that fixed point arthimetic on.

  • author's profile photo Former Member
    Former Member
    Posted on Sep 05, 2006 at 09:48 AM

    Check the type of your destination variant. If it is only TYPE I (integer) that will cut the decimals off. Use TYPE P for the destination variable also.

    Happy developing...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 05, 2006 at 09:51 AM

    Hi,

    declare target field as follows

    data :target type p decimals 3.

    target = s1 / s2.

    If target field defined is small than output is

    truncated.

    Declare your target field with no of decimals

    places required.

    Regards

    Amole

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 07, 2011 at 08:33 AM

    Hello all,

    When you can't use "fixed point arthimetic" you have to calculate factor that will allow you to get the right value because packed numbers are considered as integers.

    As an example: (consider that we don't know decimals number of each variable)

    DATA : wl_dec1 type i,

    wl_dec2 type i,

    wl_dec3 type i,

    wl_factor type i.

    DESCRIBE FIELD klmeng decimals wl_dec1.

    DESCRIBE FIELD zzntgew decimals wl_dec2.

    DESCRIBE FIELD ntgew decimals wl_dec3.

    wl_factor = 10 ** ( wl_dec1 + wl_dec2 - wl_dec3 ). " thisformula is different in case of division

    ntgew = klmeng * zzntgew / wl_factor.

    In case of division it should be :

    wl_factor = 10 ** ( wl_dec1 - wl_dec2 + wl_dec3 ). "where wl_decx correspond to varx decimals

    var1 = var2 / var3 * wl_factor.

    As a solution you can also create a function module which uses "fixed point aritmetic" in which you send values as parameters and use wanted formula as single as you would write without any conversion factor.

    Edited by: blsapsdn on Sep 7, 2011 11:45 AM

    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.