title: Why can "%.10f" % Decimal(u) emit a string with a literal colon?
body: <p>When formatting a number to be printed, 12 digit numbers are being formatted with a colon immediately after the dot. Why is this happening? This is Python 2.7 on an AIX system.</p>
  
  <pre><code>$ 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.
  &gt;&gt;&gt; '{0:.10f}'.format(123456789012)
  '123456789011.:000000000'
  &gt;&gt;&gt; from decimal import Decimal
  &gt;&gt;&gt; u=123456789012
  &gt;&gt;&gt; print "%.10f" % Decimal(u)
  123456789011.:000000000
  </code></pre>
  
  <p>Further information:</p>
  
  <p>It is not every 12 digit number:</p>
  
  <pre><code>&gt;&gt;&gt; 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
  </code></pre>
  
  <p>This is not happening with any other length numbers. Also, I tried bash's and perl's printf and this is not happening with either of them.</p>
  
  <p>What is happening here?</p>
  
  <p>As requested, here is a <a href="https://www.youtube.com/watch?v=v4PSslgH9sI" rel="noreferrer">screen shot video</a>.</p>
  
  <p>More requested information:</p>
  
  <pre><code>&gt;&gt;&gt; import locale
  &gt;&gt;&gt; locale.getdefaultlocale()
  ('en_US', 'ISO8859-1')
  </code></pre>
  
  <p>Result of user2357112 pastebin code:</p>
  
  <pre><code>&gt;&gt;&gt; import ctypes
  &gt;&gt;&gt; f=ctypes.pythonapi.PyOS_double_to_string
  &gt;&gt;&gt; f.argtypes=ctypes.c_double,ctypes.c_char,ctypes.c_int,ctypes.c_int,ctypes.POINTER(ctypes.c_int))
  &gt;&gt;&gt; f.restype=ctypes.c_char_p
  &gt;&gt;&gt; print f(123456789012.0, 'f', 10, 0, None)
  123456789011.:000000000
  </code></pre>
  
  <p>Antti_Happa's pastebin printed all numbers correctly.</p>
  
  <p>Using format r gives:</p>
  
  <pre><code>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'
  </code></pre>
  
  <p>Using e, f and g formats provided the following:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I have no access to install or update anything on this server. I can request an updated version, but change requests of this nature take a fair amount of time. Also, other programs depend on this installation and a lot of testing would be required.</p>
  
  <p>I have been informed that only IBM provided packages will be installed and that the latest python 2.7 package provided by IBM is 2.7.12.</p>
  
  <p>I have "fixed" the problem by doing</p>
  
  <pre><code>othervar = '{0:.10f}'.format(somevar).replace(':', '0')
  </code></pre>
  
  <p>which is extremely unsafe, I know, but ... <em>shrug</em></p>
  
  <p>Argh! I just noticed an off-by-one error ... <code>123456789012</code> is being formatted as one less: <code>123456789011.:0000000000</code> ... this is a weird bug.</p>