Given a value x and an integer n (assigned at runtime), I want to print x to exactly n digits after the decimal (after rounding if needed).
print(round(x, n))
works fine for (x,n)=(3.141592, 3)
but for (x,n)=(2.5,5)
, it prints just 2.5
, not 2.50000
(5 digits after decimal point).
If I knew n at runtime, say 5, I could do
@printf("%.5f", x)
But @printf being a macro needs n to be known at compile time.
Is this possible using some show
magic or something else?