In "{x:.2}", the precision .2 means "2 decimal places" for a float or "at most 2 chars"
for a str. It means nothing for other types such as int.
Wrong#
fn show(n: int): str = "{n:.2}"Fixed#
fn show(n: int): str = "{float(n):.2}"Common causes#
- Formatting an
intas if it were afloat: convert withfloat(n). - Padding was meant instead:
{n:>5}pads to width 5.