Convert float to string with given decimal points

I am making some animations with the @animate macro and would like to display time in the title.

Right now I am using string(round(t,digits=2)) but whenever the converted number has less than two decimals the text gets re-aligned resulting in a jittering effect.

animation

The command @printf("%.2",1) produces the desired output but sends it to the IO instead of a variable.

sprintf should do what you want.

1 Like

See @sprintf.

Does indeed. Thank you very much.