Modify the result after a division with multiples of 10

2,410 pts.
Tags:
AS/400
I have an expression like this Total = Quantity/10**decimal. If I have value 000080906140000 in quantity and decimal has 6, my result is 0000000080906.13. But I want it as 0000000080906.14. Is it possible?

Software/Hardware used:
As400
ASKED: October 23, 2012  8:53 AM
UPDATED: October 23, 2012  1:58 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 12  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    Is it possible?   Probably. But we need to know what language you're using and what the data definitions are. The definitions need to be changed and a minor adjustment must made to the expression.   Tom
    125,585 pointsBadges:
    report
  • RamvishakRamesh
    It is RPG, and total is declared as (15,2)
    2,410 pointsBadges:
    report
  • TomLiotta
    Okay, but what is its data type? Also, the definitions of decimal and Quantity are needed. -- Tom
    125,585 pointsBadges:
    report
  • RamvishakRamesh
    Total is a Zoned field D Total       S             15S 2  Decimal Zoned field (1,0) Quantity is Zoned field (15,0)          
    2,410 pointsBadges:
    report
  • TomLiotta
    The exponentiation and the division introduce tiny changes in the middle of the calculation. The direct way to fix this calculation:  
    eval(H) Total = Quantity/10**decimal
      The best way, though, depends on what you're actually trying to do. It'd be best just to skip calculation entirely and to extract the value directly.   Tom
    125,585 pointsBadges:
    report
  • RamvishakRamesh
    oh.. now when the Quantity is 000042777557000 and decimal is 6. total is  comming as  0000000042777.56
    2,410 pointsBadges:
    report
  • BigKat
    if what you are trying to do is just shift by decimal number of places, if you use the following code, it will cause the calculation to work without the subtle decimal position issues:total = quantity/%int(10**decimal);
    7,585 pointsBadges:
    report
  • TomLiotta
    BigKat is right. My example was a "direct way" to solve the problem that you asked about. But you didn't ask about the problem that you actually had. You originally asked about some precise values rather than describing the business problem that you are really trying to solve. Now there are new values that slightly change what the problem is.   So far, we still don't know what your real problem is. And so far, the likely best way to handle your problem hasn't been shown. Doing division with exponentiation is almost certainly not the right way.   Consider this example code (also available at Value extraction (ILE RPG) for a month):      D ds1             ds     D  Tot                          15  2 inz( 0 )     D ds2             ds     D  v1                           15  0 inz( 80906140000 )     D  t1                           11  2 overlay( v1 )     D ds3             ds     D  v2                           15  0 inz( 42777557000 )     D  t2                           11  2 overlay( v2 )      D  dec            s              1s 0 inz( 6 )       /free                Tot       = t1 ;               Tot       = t2 ;        *inlr = *on ;       return ;      /end-free You can run it in debug and check the value of Tot after both calculations.   Note that the 'dec' variable isn't needed at all for this. If dec changes for different values in this program, the problem again becomes different and a different 'best' solution can be determined.   The entrie calculation is simply [ Tot = t1 ]. No division needed, no exponentiation and no integer/decimal/truncation/rounding problem. Many times faster, too. Whenever a new series of digits is placed in v1 or v2, the result should be what you need.   But it's appropriate only for what seems to be your problem. We don't yet know what you're trying to do.   Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    This editor is totally bizarre with "code", so I made sure another copy was available at the pastebin.com site. -- Tom
    125,585 pointsBadges:
    report
  • RamvishakRamesh
    deimal value and Quantity value are taken from a file. Each time the value may be different. So I have to do the calculation part.  
    2,410 pointsBadges:
    report
  • RamvishakRamesh
    I modified the code eval(h) factor=10**decimal and then Total = Total/factor. It worked.. thanks everyone 
    2,410 pointsBadges:
    report
  • TomLiotta
    It works because of the integer math operation. But the exponentiation and the division are both slower than simply extracting the value. Using both exponentiation plus division makes it doubly slow relative to simple, direct extraction. For a single value, it's no big deal. Over many values, and possibly in many future programs doing similar work, it's a poor technique that can be error prone. -- Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following