Python 为什么“可以”。10f";%Decimal(u)发出带有文字冒号的字符串?

Python 为什么“可以”。10f";%Decimal(u)发出带有文字冒号的字符串?,python,string-formatting,aix,Python,String Formatting,Aix,格式化要打印的数字时,12位数字的格式是在点之后立即用冒号格式化的。为什么会这样?这是AIX系统上的Python 2.7 $ uname -a ; /opt/bin/python2.7 AIX myserver 1 6 00F6A5CC4C00 Python 2.7.12 (default, Sep 29 2016, 12:02:17) [C] on aix5 Type "help", "copyright", "credits" or "license" for more informatio

格式化要打印的数字时,12位数字的格式是在点之后立即用冒号格式化的。为什么会这样?这是AIX系统上的Python 2.7

$ uname -a ; /opt/bin/python2.7
AIX myserver 1 6 00F6A5CC4C00
Python 2.7.12 (default, Sep 29 2016, 12:02:17) [C] on aix5
Type "help", "copyright", "credits" or "license" for more information.
>>> '{0:.10f}'.format(123456789012)
'123456789011.:000000000'
>>> from decimal import Decimal
>>> u=123456789012
>>> print "%.10f" % Decimal(u)
123456789011.:000000000
进一步资料:

>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'ISO8859-1')
它不是每12位数字:

>>> for x in range(123456789010,123456789020):
...     print '{0:.10f}'.format(x)
...
12345678900:.0000000000
123456789010.:000000000
123456789011.:000000000
123456789013.0000000000
123456789013.:000000000
123456789015.0000000000
123456789016.0000000000
123456789017.0000000000
123456789017.:000000000
123456789019.0000000000
任何其他长度数字都不会出现这种情况。此外,我尝试了bash和perl的printf,但这两种方法都没有实现

这里发生了什么

根据要求,这里有一个

请提供更多信息:

>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'ISO8859-1')
用户2357112PasteBin代码的结果:

>>> import ctypes
>>> f=ctypes.pythonapi.PyOS_double_to_string
>>> f.argtypes=ctypes.c_double,ctypes.c_char,ctypes.c_int,ctypes.c_int,ctypes.POINTER(ctypes.c_int))
>>> f.restype=ctypes.c_char_p
>>> print f(123456789012.0, 'f', 10, 0, None)
123456789011.:000000000
Antti_Happa的pastebin正确打印了所有数字

使用格式r给出:

print 'e: {0:.10e}\nf: {0:.10f}\ng: {0:.10g}\nr: {0:0r}'.format(x)
ValueError: Unknown format code 'r' for object of type 'int'
使用e、f和g格式提供以下内容:

for x in range(123456789000,123456789019):
print 'e: {0:.10e}\nf: {0:.10f}\ng: {0:.10g}'.format(x)
e: 1.2345678900e+11
f: 123456789000.0000000000
g: 1.23456789e+11
e: 1.2345678900e+11
f: 123456789000.:000000000
g: 1.23456789e+11
e: 1.2345678900e+11
f: 123456789001.:000000000
g: 1.23456789e+11
e: 1.2345678900e+11
f: 123456789003.0000000000
g: 1.23456789e+11
我无权在此服务器上安装或更新任何内容。我可以请求更新版本,但这种性质的更改请求需要相当长的时间。另外,其他程序依赖于此安装,需要进行大量测试

我被告知,只有IBM提供的软件包将被安装,IBM提供的最新python 2.7软件包是2.7.12

我已经通过这样做“修复”了这个问题

othervar = '{0:.10f}'.format(somevar).replace(':', '0')
这是非常不安全的,我知道,但是。。。耸耸肩

啊!我刚刚注意到一个错误<代码>123456789012的格式为少一个:
123456789011.:0000000000
。。。这是一个奇怪的bug。

虽然不是一个“答案”,但我可以在AIX上运行的稍新版本上给出我的结果

很抱歉,我无法复制您的问题

[lholtscl@ibm3 ~]$ python
Python 2.7.13 (default, Sep  7 2017, 21:08:50) [C] on aix7
Type "help", "copyright", "credits" or "license" for more information.
>>> print "%.10f" % 123456789012
123456789012.0000000000
>>> '{0:.10f}'.format(123456789012)
'123456789012.0000000000'

无法在任何python版本上复制。我们通常不会要求这样做,但您可以发布此行为的屏幕截图吗?请提供
locale.getdefaultlocale()
的输出。对于其他想要深入了解源代码的人,请提供2.7.12 python源代码树。我怀疑问题最终可能源于Python所依赖的一些基本库例程的AIX实现中的一个bug。
字符出现在ascii中的
9
之后。事实上,如果您将这些
视为在该点的
10
的数值相等,则输出在技术上是正确的。谢谢。我可以用你的评论来推动python的更新。