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) %}
I guess you could use the trick that the last digit of a number is its modulo 10.
{% set num_last = number % 10 %}
1 Like
keats
3
In the next version you should be able to do something like {% set num_last = (number | str)[-1] %} i think?
1 Like
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.
1 Like