cancel
Showing results for 
Search instead for 
Did you mean: 

Div & Mod, a maths question

Former Member
0 Kudos

Hello,

Can anyone explain why I get the following results in abap?

-129 mod 60 = 51

-129 div 60 = -3

In .net you get -9 and 2 which I would say is correct. I've spotted that (-3x60)+51=-129 , but I can't explain mathematically why sap is giving -3 especially when .net and my logic says it should be -2.

Kind regards

Ash Thomas

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

hi thomas,

DIV gives u the rounded result of ur division, if u wants the decimal part go for '/' instead of DIV and MOD gives u remainder of ur division.

regards,

pritam.

Answers (1)

Answers (1)

Former Member
0 Kudos

-129 mod 60 = 51

-129 div 60 = -3

1. -129 mod 60 = 51

-129 mod 60 => ( -9 mod value is -ve but mod value only +ve so 60 - 9 = 51.

MOD - Integer remainder of the division of the left by the right operand

2. -129 div 60 = -3

if use -129/60 = -2.15.

but if use -129 DIV 60 = -3 here 0.15 => 1 so decimals convert interger.

if have any decimals value ( low or high ) it convert to one for using DIV.

DIV - Integer portion of the division of the left by the right operand

if you want Ans -2 using ' / '

-129 / 60 = -3.

Thanks,

Durai.V

Former Member
0 Kudos

Not sure I understood that, but thanks.

The simple solution was to make negative values positive.

Kind regards

Ash Thomas

Sap Consultant