[issue20811] str.format for fixed width float can return a string longer than the maximum specified

aubmoon report at bugs.python.org
Sun Mar 2 00:04:35 CET 2014


aubmoon added the comment:

That is exactly what I tried first. It turns out in the particular case I
have been working the 8th digit is needed for correct answers. The job is a
port of a punch card FORTRAN system into something more modern. The catch
is the system is a scientific application that protects life, limb, and
treasure. The new system must inter-operate with the legacy system until
the entire system can be replaced with VV&A software under configuration
control. In my particular case the sign must be printed, the decimal must
be printed, and all eight digits. The number is always strictly -1 < x < 1
and has eight significant digits. The number is the included in a larger
string of data. What I have done to address the issue is format the x
string separately from the rest of the data and then slice and join
out the undesired
leading 0. Then include the value as a %s format in the larger context.

On Saturday, March 1, 2014, Stefan Krah <report at bugs.python.org> wrote:

>
> Stefan Krah added the comment:
>
> aubmoon: Would it be a possibility just to use 'f' instead?
>
> >>> "{:+10.7f}".format(1.12345678)
> '+1.1234568'
> >>> "{:+10.7f}".format(0.12345678)
> '+0.1234568'
>
> ----------
> nosy: +skrah
>
> _______________________________________
> Python tracker <report at bugs.python.org <javascript:;>>
> <http://bugs.python.org/issue20811>
> _______________________________________
>

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20811>
_______________________________________


More information about the Python-bugs-list mailing list