'Python deprecated string formatting to percentage for floats from 0.0 to 1.0 [duplicate]

I want to add bar_labels to plots generated by Matplotlib. The interface uses the old Python string formatting annotations to render the labels, for example:

Value: 0.8fmt="%.1f%%" → produces 0.8% as output

I am searching for an expression which also multiplies the value by 100, so that the example would result in 80,0%. It is unfortunately not possible to use more recent string format options that Python offers.

The format options have to be included in the function call, for example: ax.bar_label(ax.containers[0], fmt="%.1f%%")

See also in the documentation.



Solution 1:[1]

Try like

"{:.1%}".format(0.8)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Karthikeyan S