# Getting the last digit of a number

**URL:** <https://zola.discourse.group/t/getting-the-last-digit-of-a-number/2944>\
**Category:** Support\
**Created:** [May 15, 2026, 8:51am UTC](https://zola.discourse.group/t/getting-the-last-digit-of-a-number/2944 "2026-05-15T08:51:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthillco](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/matthillco/32/869_2.png) [@matthillco](https://zola.discourse.group/u/matthillco)\
**Post date:** [May 15, 2026, 8:51am UTC](https://zola.discourse.group/t/getting-the-last-digit-of-a-number/2944/1 "2026-05-15T08:51:48Z")

</div>

I do this arcane thing to get the last digit of an integer, which seems a bit… long. Is there an easier way that I’ve missed?

`{% set num_last = number | as_str | split(pat="") | slice(start=-2, end=-1) | join(sep="") | int() %}`

It would be nice just to do something similar to last items in arrays:

`{% set num_last = number | last %}`

Perhaps `last` could take a parameter, to change its function:

`{% set num_last = number | last(type=character|word|digit) %}`

---

<div class="post-metadata">

**Author:** ![Colas.Nahaboo](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/colas.nahaboo/32/1610_2.png) [@Colas.Nahaboo](https://zola.discourse.group/u/Colas.Nahaboo)\
**Post date:** [May 15, 2026, 7:35pm UTC](https://zola.discourse.group/t/getting-the-last-digit-of-a-number/2944/2 "2026-05-15T19:35:02Z")

</div>

I guess you could use the trick that the last digit of a number is its modulo 10.

`{% set num_last = number % 10 %}`

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [May 17, 2026, 2:46pm UTC](https://zola.discourse.group/t/getting-the-last-digit-of-a-number/2944/3 "2026-05-17T14:46:07Z")

</div>

In the next version you should be able to do something like `{% set num_last = (number | str)[-1] %}` i think?

---

<div class="post-metadata">

**Author:** ![matthillco](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/matthillco/32/869_2.png) [@matthillco](https://zola.discourse.group/u/matthillco)\
**Post date:** [June 7, 2026, 9:22pm UTC](https://zola.discourse.group/t/getting-the-last-digit-of-a-number/2944/4 "2026-06-07T21:22:19Z")

</div>

> I guess you could use the trick that the last digit of a number is its modulo 10.
> 
> `{% set num_last = number % 10 %}`

Oh my goodness, I completely forgot about modulus! That’s a very simple, elegant solution, thank you.
