- [WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you.
- New Version of MetaTrader 4 Client Terminal Build 418
- Problem with simple mathematic calculation.

**CHARLESS11:**

If you are having a problem with dividing two integer variables in MQL4. This may be your fix!!

Wrong! It will give you an integer part of the result'

Ie. 5/2 will result in 2

**Keith Watford:**

Wrong! It will give you an integer part of the result'

Ie. 5/2 will result in 2

**CHARLESS11:**

You misunderstood the issue! The problem is not with integers or whole numbers. The problem happens with "int type defined variables" and not just simple division of two whole numbers!!

I don't think that I misunderstood anything.

You said

**CHARLESS11:**

and that is not true (unless the result is less than 1).

int a=5; int b=2; double res=a/b; Print("a/b = ",res);

will print 2.0 which is definitely not zero.

**Keith Watford:**

I don't think that I misunderstood anything.

You said

and that is not true (unless the result is less than 1).

will print 2.0 which is definitely not zero.

**CHARLESS11:**

If these two numbers were calculated to be 200/400, "res" even defined as a double would calculate as zero instead of 0.5.

If they were integer values calculated to 200 and 400, then of course, 200/400 will calculate to 0 because 0.5 is less than 1. The integer part of the result is zero.

Now, if they were calculated to 600 and 400, then 600/400 will calculate to 1, which is the integer part of 1.5

So I repeat....

**CHARLESS11:**

**Keith Watford:**

Wrong! It will give you an integer part of the result'

**CHARLESS11:**

**CHARLESS11:**

I am not in here to argue with you, but rather to help anyone new to programming about this issue.

Yet you keep arguing!

Yes, it is important that newbies understand about this issue, but it is also important that they are given the correct information. In your first post you stated that int/int returns zero and that is wrong. It will only return zero if the result is less than 1. int/int returns the integer part of the result.

**CHARLESS11:**

now, that is correct because the result will be less than 1 so the integer part of the result will be zero.

**CHARLESS11:**

If you are having a problem when dividing a small integer by a larger integer variables in MQL4. This may be your fix!!

Thanks, this was helpful

**David Muriithi:**

Thanks, this was helpful

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets

You agree to website policy and terms of use