gmpy icon indicating copy to clipboard operation
gmpy copied to clipboard

"Invalid conversion specification" error for align '=' value in format spec

Open skirpichev opened this issue 6 months ago • 1 comments

>>> from gmpy2 import *
>>> f"{mpfr('123.456'):=.5g}"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid conversion specification
>>> f"{float(mpfr('123.456')):=.5g}"  # works for python floats
'123.46'

I think we should be compatible with python floats here, meaning '=' is: "Forces the padding to be placed after the sign (if any) but before the digits. This is used for printing fields in the form ‘+000000120’. This alignment option is only valid for numeric types. It becomes the default for numbers when ‘0’ immediately precedes the field width."

skirpichev avatar Aug 06 '24 07:08 skirpichev