How to get remainder of a division.

How to get remainder of a division.

sbadavath
Observer Observer
1,108 Views
3 Replies
Message 1 of 4

How to get remainder of a division.

sbadavath
Observer
Observer

Hi all,

I am new to iLogic & don't know much about coding, need help with this.

 

Say I have A=Some_number (10 for explanation's sake) & B=Another_number (3 for this example).
X=Remainder of (A/B) which is 1 here.

X=1.

How do write this in iLogic.

 

Thanks in advance.

0 Likes
Accepted solutions (1)
1,109 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Get 'absolute' value of A/B, then subtract the Integral part of that value, to get the remainder, which in this case is .333___.  Then multiply that remainder by B, to get the remaining portion of 3 that remains.

 

A = 10
B = 3
X = Abs((A / B) -Truncate(A / B))
MsgBox("X = " & X, , "")
MsgBox("X*B = " & X * B, , "")

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

Curtis_Waguespack
Consultant
Consultant

Hi @sbadavath 

 

Welcome to the forum.

 

In addition to WCrihfield's method you can use the Mod operator to find the remainder also:

 

x = 10 Mod 3

MsgBox(x)

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 4 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @sbadavath.  There is actually a much simpler way to do this...I don't know why I didn't think of this before.  You can use the 'Mod' operator.  This is precisely what it was made for.  Here is a link to its official description.

A = 10
B = 3
Y = A Mod B
MsgBox("Y = " & Y, , "")

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes