I am trying to display sig figs in a string and I have found the '{:.2f}'.format(x) style and it works great as long as I have the number of sig figs as an integer in the code, but I cannot seem to get this style of formatting to work if the number of sig figs is contained in a variable. 2 works sig=2 doesn’t. I have been trying to use the % along with .format to insert sig like this '{:.%if}'.format(x) %sig', but it doesn’t work.
I am sure there is a very simple elegant solution to this, but I cannot figure it out. Any help would be greatly appreciated. Thanks.
You can actually use string format substitution to supply parameters to the format string itself: