Page 1 of 2

Value truncating after multiplication

PostPosted: Sat Mar 29, 2014 2:09 am
by shankar_dh
Hi,

I am multiplying below 2 variables
Var1 --> 8,16,PD
Var2 --> 29,15,ZD [Its 9(5)v9(10)]
Below is the input file
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
IDPBBD    b  b b b %     000010000000000031714                       
CCDCCC0023862286283862600000FFFFFFFFFFFFFFFFFFFFF44444444444444444444444
9472240470223322320223C0000100001000000000003171400000000000000000000000
-----------------------------------------------------------------------


After multiplication below is the output file,Multiplied value starts from position 39
----+----1----+----2----+----3----+----4----+----5----+----6----+----
***************************** Top of Data ***************************
IDPBBD    b  b b b %0000100000000002323826223823082622360000000000
CCDCCC00238622862838626FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
9472240470223322320223C0000100000000002323826223823082622360000000000


Expected output +4,273,082,622,323,826,223,823,082,622.36 X 1.0000000000 = +4,273,082,622,323,826,223,823,082,622.36
What I am getting ------------>> +2,323,826,223,823,082,622.36

SORT card I have used,
SORT FIELDS=COPY                                                     
OUTREC IFTHEN=(WHEN=INIT,                                           
BUILD=(1:1,23,24:29,15,39:(8,16,PD,MUL,29,15,ZD),72:25,4,195:36,6)) 


Please let me know how to avoid this truncation.

Re: Value truncating after multiplication

PostPosted: Sat Mar 29, 2014 3:38 am
by BillyBoyo
You have a 30-digit number. You shifted it left 10 digits. It can be a maximum of 31 digits. So you lost the leading nine digits.

Why do you have such a huge value?

Re: Value truncating after multiplication

PostPosted: Sat Mar 29, 2014 9:40 am
by shankar_dh
Thanks Billy for the reply. This is the value of sum of account numbers, Account numbers might be millions. So, what if I get such a huge value in production.
It should be a problem.
Is there anyway to avoid it??

Re: Value truncating after multiplication

PostPosted: Sat Mar 29, 2014 9:30 pm
by dick scherrer
Hello,

Why does someone believe it is a good idea to do arithmetic on account numbers?

Sounds like a design issue . . .

Re: Value truncating after multiplication

PostPosted: Sat Mar 29, 2014 10:18 pm
by enrico-sorichetti
Account numbers might be millions. So, what if I get such a huge value in production.

You will be out of luck :mrgreen:

the 31 decimal digits is somehow carved in stone
the problem should have been spotted when designing the application !

Re: Value truncating after multiplication

PostPosted: Sun Mar 30, 2014 5:51 am
by BillyBoyo
Summed account numbers? I don't think so. How do you get 0.36 of an account number? You have a value which would allow for about a billion 20-digit account numbers, ignorigin the decimals. That's too many account, with too many digits.

Nope, doesn't make sense, There is more in there than account numbers.

What are you multipling them by, and why?

Re: Value truncating after multiplication

PostPosted: Sun Mar 30, 2014 1:31 pm
by NicC
Perhaps what he means is "account balances" but, unless the company is planning to take over all the accounts in the world I somehow do not think he will need a field that big!

Re: Value truncating after multiplication

PostPosted: Sun Mar 30, 2014 1:50 pm
by enrico-sorichetti
we might have hit a terminology barrier.
in italian banking jargon the numbers are the balance times the number of days
and it is used when computing the interests

wonder if it is something like that?

Re: Value truncating after multiplication

PostPosted: Sun Mar 30, 2014 6:20 pm
by shankar_dh
Hi Everyone..

Thanks for all your reply,
Yes, Nic is correct. I meant Account balance.
Yes, I know 31 digits is a huge number. We wont be getting such a huge balance but our design should be in a position to handle it , so I was thinking in that line.
Now, I have replace SORT with SAS just for the multiplication. Rounding is a big problem is SORT, I wish we had a function to round a value like in COBOL ROUNDING.

Regards,
Shankar.

Re: Value truncating after multiplication

PostPosted: Mon Mar 31, 2014 4:19 am
by BillyBoyo
You haven't said what that multiplier is and why you need it. What are the valid ranges for it? In algebra, dividing by the inverse is the same as multiplication. Depending on the range of that 9(5)V9(10) you may be able to divide. You could try dividing that number by one, which is the same as multiplying by one, but without requiring 46 digits, but the magnitude of your value could still require more than 31 digits, so again you'd get truncation.

I'm surprised SAS can deal with 46 digits in an intermediate value with multiplication, but if it does, it does.

Rounding is not a problem for SORT, it just rounds down. What you mean is you want a different rounding. What rounding do you want, specifically.