Skip to content

clap help trims .0 from float default values #6249

@SzilvasiPeter

Description

@SzilvasiPeter

Please complete the following tasks

Rust Version

rustc 1.93.0 (254b59607 2026-01-19)

Clap Version

4.5.57

Minimal reproducible code

use clap::Parser;

#[derive(Parser, Debug)]
struct Args {
    #[arg(short = 'a', default_value_t = 1.0)]
    amplify: f32,
}

fn main() {
    let _ = Args::parse();
}

Steps to reproduce the bug with the above code

  1. Build and run cargo run -- --help from any workspace containing the code above.
  2. Observe the generated help text line for -a argument.
Usage: playground [OPTIONS]

Options:
  -a <AMPLIFY>  [default: 1]
  -h, --help    Print help

Actual Behaviour

Clap displays the default as [default: 1] even though the default_value_t is 1.0.

Expected Behaviour

The help text should show [default: 1.0] for the --amplify argument, so the default is clearly presented as a floating-point value matching the configured literal.

Additional Context

If the 1.1 value is specified, then it displays the default value properly. The zero decimal (X.0) numbers are trimmed.

Debug Output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-triageStatus: New; needs maintainer attention.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions