# Can't get two variables to divide

**URL:** <https://community.hubspot.com/t/cant-get-two-variables-to-divide/63244>\
**Category:** CMS Development\
**Created:** [August 18, 2022, 1:45pm UTC](https://community.hubspot.com/t/cant-get-two-variables-to-divide/63244 "2022-08-18T13:45:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![AKoprivec](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@AKoprivec](https://community.hubspot.com/u/AKoprivec)\
**Post date:** [August 18, 2022, 1:45pm UTC](https://community.hubspot.com/t/cant-get-two-variables-to-divide/63244/1 "2022-08-18T13:45:04Z")

</div>

For some reason i can do every operation except for diving theese 2 variables. I’ve tried every aleternative to round them and still nothing changes. The code first sum’s up an array with numbers it got from a for loop. Heres the code:  
{% set number1 = list\_number|sum|round(1) %}  
{% set number = numbers|sum|multiply(10)|round(1) %}

{{ number / number1 }}

and this is the error it comes up with when i try to publish:

1. Error:Cannot resolve property

Any help would be appreciated

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 18, 2022, 2:21pm UTC](https://community.hubspot.com/t/cant-get-two-variables-to-divide/63244/2 "2022-08-18T14:21:45Z")

</div>

Hi @AKoprivec,

what are **list\_number** and **numbers**? Are they set before your calculation?

You have to define them somehow, see this: [HubL filters - HubSpot docs](https://developers.hubspot.com/docs/cms/reference/hubl/filters) . For example like this:

```lia-code-sample
{% set list_number = 2 %}
{% set numbers = 5 %}
{% set number1 = list_number|sum|round(1) %}
{% set number = numbers|sum|multiply(10)|round(1) %}

{{ number / number1 }}

```

Here are more resources that can help:

- [Operators & Expression Tests - HubSpot docs](https://developers.hubspot.com/docs/cms/reference/hubl/operators-and-expression-tests)
- [Debugging methods and error types - HubSpot docs](https://developers.hubspot.com/docs/cms/start-building/introduction/developer-environment/troubleshooting)

best,

Anton

_Moderator note: While this solution may not address the original poster’s specific situation, it could be helpful for other community members facing similar challenges._

---

<div class="post-metadata">

**Author:** ![AKoprivec](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@AKoprivec](https://community.hubspot.com/u/AKoprivec)\
**Post date:** [August 18, 2022, 2:26pm UTC](https://community.hubspot.com/t/cant-get-two-variables-to-divide/63244/3 "2022-08-18T14:26:25Z")

</div>

Hi Anton,  
yes they are both defined before as arrays  
{% set numbers = [] %}  
{% set list\_number = [] %}  
but since they are converted with |sum it should be fine?  
Best  
Anze

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 18, 2022, 2:43pm UTC](https://community.hubspot.com/t/cant-get-two-variables-to-divide/63244/4 "2022-08-18T14:43:51Z")

</div>

Yes,

but if they’re empty there is nothing “to sum up”. And this means that the outcome can’t be calculated.

You can populate it with (contact) properties, module functions or whatever you like - but the array can’t be empty

best,

Anton

---

<div class="post-metadata">

**Author:** ![AKoprivec](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@AKoprivec](https://community.hubspot.com/u/AKoprivec)\
**Post date:** [August 18, 2022, 2:47pm UTC](https://community.hubspot.com/t/cant-get-two-variables-to-divide/63244/5 "2022-08-18T14:47:25Z")

</div>

Yes the array isnt empty, just using {{ number }} and {{ number1 }}  
displays both numbers (assuming as integers since other operations work )  
just fine. Is there maybe any other way to run variables out of the for  
loop without appending the numbers to an array  
best,  
Anže

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 19, 2022, 6:13am UTC](https://community.hubspot.com/t/cant-get-two-variables-to-divide/63244/6 "2022-08-19T06:13:17Z")

</div>

Hi @AKoprivec,

could you please provide the whole code?

Also if the numbers are set in the module - do you have set a default number?

best,

Anton

---

<div class="post-metadata">

**Author:** ![AKoprivec](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@AKoprivec](https://community.hubspot.com/u/AKoprivec)\
**Post date:** [August 19, 2022, 6:20am UTC](https://community.hubspot.com/t/cant-get-two-variables-to-divide/63244/7 "2022-08-19T06:20:07Z")

</div>

Hi @Anton  
Yes ofcourse, here is the whole code:

```lia-code-sample
{% set list_variable = request_contact.list_memberships %}
{% set numbers = [] %}
{% set list_number = [] %}

{% for i in module.questions %}
 {% for list in i.lists %}
 {% if list.list_id in list_variable %}
 {% do numbers.append(list.list_value) %}
 {% endif %}
 {% endfor %}
 {% do list_number.append(1) %}
{% endfor %}

{% set number1 = list_number|sum|round(0) %}
{% set number = numbers|sum|multiply(10)|round(0) %}

```

The module gets all of the contacts lists and checks which of them are the same as the ones input into fields and then assigns them the corresponding value. The top part of the script should work fine, as the end result is 2 numbers. Every single operation between them works just fine except for / and //. And yes all the modules have a set default number of 0 (both list\_id and list\_value).

thank you for your help,

best,

anže

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [August 19, 2022, 2:00pm UTC](https://community.hubspot.com/t/cant-get-two-variables-to-divide/63244/8 "2022-08-19T14:00:11Z")

</div>

@AKoprivec If you add {{ number }} and {{ number1 }} at the very end of the code what do the variables return (note that you can’t divide by zero, so if they’re returning the default value it’s going to error out)?

---

<div class="post-metadata">

**Author:** ![AKoprivec](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@AKoprivec](https://community.hubspot.com/u/AKoprivec)\
**Post date:** [August 22, 2022, 6:31am UTC](https://community.hubspot.com/t/cant-get-two-variables-to-divide/63244/9 "2022-08-22T06:31:47Z")

</div>

They both return a number, all operations besides / and // work completly fine on both numbers, and it doesn’t show any red alerts saying it can’t devide with 0 like it does if i do {{number}}/0 instead it just gives an orange alert on that line.
