it is easy to output 9 which is aligned by the right with a space of 2 characters
import strformat
echo fmt"{9:>2d}"
but what if the width is a var, how can we do the string format? What I mean
var width = 2
echo fmt"{9:>{width}d}"
Thanks
fmt works using compile time logic, so the way to do it would be to use strutils.align as such
import std/strutils
var width = 2
assert align($9, width) = " 9"