Skip to content

Float string formatting with no specified presentation type behavior. #99694

@jagerber48

Description

@jagerber48

Documentation

The string format specification mini language is used to customize the presentation floats (and other types) as strings. Details like the minimum field with and precision of the representation of the float can be controlled. Documentation for the mini language is found at https://docs.python.org/3/library/string.html#format-specification-mini-language.

In the documentation it states that

For float this is the same as 'g', except that when fixed-point notation is used to format the result, it always includes at least one digit past the decimal point. The precision used is as large as needed to represent the given value faithfully.

However, I don't find this to be the case in practice:

value = 3141500.0
print(value)
print(f'{value:}')
print(f'{value:g}')

results in

3141500.0
3141500.0
3.1415e+06

Is there accurate documentation about the expected formatting of floats when presentation type is not specified? If not could someone describe the expected behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions