## HubL: Output average number from array

SOLVE
Regular Contributor

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

1 Accepted solution

Accepted Solutions
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@Rich_Bibblio

```//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)}}```

tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

Drop by and say Hi to me on slack.

2 Replies
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@Rich_Bibblio

```//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)}}```

tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

Drop by and say Hi to me on slack.

Highlighted
Regular Contributor

Hi Tim,

This is perfect in every way. Thanks so much!

Rich