# HubL: Output average number from array

**URL:** <https://community.hubspot.com/t/hubl-output-average-number-from-array/10596>\
**Category:** CMS Development\
**Created:** [October 16, 2018, 11:22am UTC](https://community.hubspot.com/t/hubl-output-average-number-from-array/10596 "2018-10-16T11:22:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rich\_Bibblio](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rich_bibblio/32/41983_2.png) [@Rich\_Bibblio](https://community.hubspot.com/u/Rich_Bibblio)\
**Post date:** [October 16, 2018, 11:22am UTC](https://community.hubspot.com/t/hubl-output-average-number-from-array/10596/1 "2018-10-16T11:22:49Z")

</div>

Hi all,  
**A HubL puzzle:**  
Take a long integer, put each digit into an array, output the average.  
E.g. input is 6314095485.  
Array becomes [6, 3, 1, 4, 0, 9, 5, 4, 8, 5]  
Average = 4.5  
How is this written in HubL?  
Many thanks!  
Rich

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [October 16, 2018, 1:19pm UTC](https://community.hubspot.com/t/hubl-output-average-number-from-array/10596/2 "2018-10-16T13:19:50Z")

</div>

[@Rich\_Bibblio](https://community.hubspot.com/t5/user/viewprofilepage/user-id/63642)

```auto
//starting number{% set num = 6314095485 %}//convert it to string
{% set numAsString = num+"" %}//convert the string to a list and add each number
{% set numSum = numAsString|list|sum %}//sanity check; get the length of the list
{% set numCount = numAsString|list|length %}//division; use the float filter to keep from rounding up/down to integer
{{(numSum|float / numCount)}}

```

* * *

If this answer helped, please, mark as solved 😄

* * *

[tim@belch.io](mailto:tim@belch.io) | [forms.belch.io](https://forms.belch.io) | Design your own Beautiful HubSpot Forms; No coding necessary.

Drop by and say Hi to me [on slack](http://slack.belch.io/).

---

<div class="post-metadata">

**Author:** ![Rich\_Bibblio](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rich_bibblio/32/41983_2.png) [@Rich\_Bibblio](https://community.hubspot.com/u/Rich_Bibblio)\
**Post date:** [October 16, 2018, 11:30pm UTC](https://community.hubspot.com/t/hubl-output-average-number-from-array/10596/3 "2018-10-16T23:30:20Z")

</div>

Hi Tim,

This is perfect in every way. Thanks so much!

Rich
