Skip to content

Formatting mpf's is incompatible with Python if formatting type is missing #856

@skirpichev

Description

@skirpichev

Documentation says: "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."

While we have:

>>> f'{mp.mpf(1.23456789):}'  # fixed precision=6
'1.23457'
>>> f'{mp.mpf(1):}'  # no trailing 0
'1'

Note, that it might be non-trivial to match exactly Python's output, because e.g. CPython and mpmath use different decimal approximations for some floats. E.g.:

>>> mp.mpf(0.3976135751111121)
mpf('0.39761357511111212')
>>> 0.3976135751111121
0.3976135751111121
>>> 0.39761357511111212
0.3976135751111121

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions