# Am I using 'Mod' correctly

**URL:** <https://forum.xojo.com/t/am-i-using-mod-correctly/30505>\
**Category:** General\
**Created:** [March 26, 2016, 4:40pm UTC](https://forum.xojo.com/t/am-i-using-mod-correctly/30505 "2016-03-26T16:40:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Budd](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_budd/32/799_2.png) [@Paul\_Budd](https://forum.xojo.com/u/Paul_Budd)\
**Post date:** [March 26, 2016, 4:40pm UTC](https://forum.xojo.com/t/am-i-using-mod-correctly/30505/1 "2016-03-26T16:40:29Z")

</div>

I am trying to split a number into years and months, but Mod operator does not want to play. I basically want to get the average age in a format of x yrs and x months rather than yrs.fraction of year. It may just be the fact I have a long day and I am doing something silly.

[code]yr=avgage/listbox1.listcount 'avgage is a total of all ages, listcount is the number of entries, gives an iteger correctly of year

yr=avgage\listbox1.listcount ’ gives me say for example 41.24, 41 years and .24 of a year, roughly 3 months

mth=avgage mod listbox1.listcount 'does not give me the .24 as above as I would expect, it gives me 680?, which I can then multiply by 12 to get months  
[/code]

Any clues?

Desktop, windows.

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [March 26, 2016, 5:13pm UTC](https://forum.xojo.com/t/am-i-using-mod-correctly/30505/2 "2016-03-26T17:13:47Z")

</div>

How much is avgage?  
How much is listbox1.listcount?  
By the way why is avgage the total of all ages, while a reader would interpret this variable as average of ages?

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [March 26, 2016, 5:21pm UTC](https://forum.xojo.com/t/am-i-using-mod-correctly/30505/3 "2016-03-26T17:21:00Z")

</div>

Modulo gives you the remainder of a division.

207 / 13 -\> 15.9230769230769234  
207 \ 13 -\> 15  
207 Mod 13 -\> 12  
which is: 13 \* 15 = 195 + 12

---

<div class="post-metadata">

**Author:** ![Paul\_Budd](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_budd/32/799_2.png) [@Paul\_Budd](https://forum.xojo.com/u/Paul_Budd)\
**Post date:** [March 26, 2016, 5:22pm UTC](https://forum.xojo.com/t/am-i-using-mod-correctly/30505/4 "2016-03-26T17:22:09Z")

</div>

Eli,

In answer to your questions,

avgage is 116464.50999999972  
listcount is 2824

My variable should be name totalofallages you are correct, i was a ‘newbie’ when I first wrote it 🙂 lol

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [March 26, 2016, 5:26pm UTC](https://forum.xojo.com/t/am-i-using-mod-correctly/30505/5 "2016-03-26T17:26:22Z")

</div>

Maybe something like this:

```auto
Dim days As Integer = 365 * ((116464.50999999972 / 2824) - (116464.50999999972 \\ 2824))
```

---

<div class="post-metadata">

**Author:** ![Paul\_Budd](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_budd/32/799_2.png) [@Paul\_Budd](https://forum.xojo.com/u/Paul_Budd)\
**Post date:** [March 26, 2016, 5:45pm UTC](https://forum.xojo.com/t/am-i-using-mod-correctly/30505/6 "2016-03-26T17:45:23Z")

</div>

Thanks for the prod Eli, i was missing the deduct one from the other ☹ to leave the ‘balance’, and use that in my calculation.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:14pm UTC](https://forum.xojo.com/t/am-i-using-mod-correctly/30505/7 "2020-10-29T18:14:35Z")

</div>


