Skip to content

Text formatting: a leading zero on the minimum width should really mean leading zero #39997

Closed
@jimblandy

Description

@jimblandy

In a string format, the leading zero on a minimum width is treated as a padding character. It would make more sense for it to be treated strictly as a leading zero. The status quo permits strange things like this:

assert_eq!(format!("{:<04}", 1), "1000");

Either " 1" or "0001" would be better answers than one that changes the numeric value.

Just to be clear, I agree that this behavior is correct:

assert_eq!(format!("{:0<4}", 1), "1000");

This case uses 0 as its padding character, so you deserve whatever you get.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-help-wantedCall for participation: Help is requested to fix this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions