Percent with two decimals in a fixed-width column FRFreyaLOP 16 Oct, 21:48 99.80% — how do I keep the trailing zero?
EMEmmaCodes16 Oct, 23:56replies: 2Use a format spec with two decimals and a width, e.g. right-aligned .2f followed by "%". Rounding with round() would drop the trailing zero; formatting keeps it.
OLOllieGrant18 Oct, 11:33"text".center(WIDTH) for the title is neat. Didn't know strings had center().
Comments 4
Join the discussion CommentAlready have an account? Log in
Use a format spec with two decimals and a width, e.g. right-aligned
.2ffollowed by "%". Rounding with round() would drop the trailing zero; formatting keeps it.Formatting, not rounding. Again 😄
Also ljust() and rjust(). Handy for quick tables.
"text".center(WIDTH)for the title is neat. Didn't know strings had center().