Convert Integer to String Jinja
I Have an Integer {% Set curYear = 2013 %} in {% If %} Statement I Have to Compare It with Some String. I Can't Set curYear to String at the Beginning Because...
I have an integer
{% set curYear = 2013 %}
In {% if %} statement I have to compare it with some string. I can't set curYear to string at the beginning because I have to decrement it in loop.
How can I convert it?
3 Answers
I found the answer.
Cast integer to string:
myOldIntValue|string
Cast string to integer:
myOldStrValue|int
The OP needed to cast as string outside the {% set ... %}.
But if that not your case you can do:
{% set curYear = 2013 | string() %}
Note that you need the parenthesis on that jinja filter.
If you're concatenating 2 variables, you can also use the ~ custom operator.
could use this on set_fact in ansible
'{0:d}'.format(myOldIntValue)