# Android QuestionInterger Division

#### pixelpop

##### Active Member
I have searched the forum and found some discussion on a "missing" math function, specifically the integer divider function. Not having found an implementation of either "\" or "div", what is the proper way to divide two integers and return the correct answer?

If "55 / 10" returns 5 then what function do I use to return 5.5?

#### techknight

##### Well-Known Member
I always used MOD to return a remainder.

#### pixelpop

##### Active Member
55 MOD 5 returns 5 also. That still doesn't get me the correct answer of 5.5.

#### mangojack

##### Well-Known Member
This works ?
B4X:
``````Dim  num1 = 55 As Int
Dim  num2 = 10 As Int

Label1.Text = num1 / num2  'result = 5.5``````

#### stevel05

##### Expert
You can assign the result of the calculation to a float or a double.

#### pixelpop

##### Active Member
Well, duhhh....I tried Int and Long. Of course it would be one that I didn't try! Thanks!!

#### Erel

Staff member
55 / 10 returns 5.5.

B4X:
``Log(55/10)``

#### pixelpop

##### Active Member
Not if all three numbers are Dim'ed as Int variables. For instance:

Dim weight As Int
Dim scale_packet(6) As Int
-------
weight = scale_packet(4) / 10

If scale_packet(4) = 55 then weight will return 5, not 5.5.

But if weight is Dim'ed as Double, weight returns the correct 5.5.

#### Erel

Staff member
55/10 returns 5.5. If you store this value in an Integer variable then it will be 5. It is not related to the division.

#### pixelpop

##### Active Member
You are right, and that was my error. Based on stevel05's comment, I changed weight from an Int to a Double and all is right with the world.

Replies
1
Views
214
Android Question WhatsApp Interaction
Replies
4
Views
399
Replies
2
Views
258
Replies
3
Views
277
Replies
4
Views
3K