<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2658.2">
<TITLE>Floating point -&gt; string conversions</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>There's a thread in the standard list (with this very Subject) that talks about implicit coercing with &quot;%d&quot; in strings replacement.</FONT></P>

<P><FONT SIZE=2>jfouhy posted this example:</FONT>
</P>

<P><FONT SIZE=2>&gt;&gt;&gt; pow(2, 31)</FONT>
<BR><FONT SIZE=2>2147483648L</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; '%d' % 2147483647.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # python will convert to int</FONT>
<BR><FONT SIZE=2>'2147483647'</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; '%d' % 2147483648.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # too big for an int, so error.</FONT>
<BR><FONT SIZE=2>Traceback (most recent call last):</FONT>
<BR><FONT SIZE=2>&nbsp; File &quot;&lt;stdin&gt;&quot;, line 1, in ?</FONT>
<BR><FONT SIZE=2>TypeError: int argument required</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; '%d' % long(2147483648.0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # but yet, no trouble accepting a long.</FONT>
<BR><FONT SIZE=2>'2147483648'</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; '%d' % int(2147483648.0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # and int() converts to long anyway</FONT>
<BR><FONT SIZE=2>'2147483648'</FONT>
</P>
<BR>

<P><FONT SIZE=2>I think that here's a bug, but don't know where:</FONT>
</P>

<P><FONT SIZE=2>Should %d accept only integer values? So this is a bug:</FONT>
</P>

<P><FONT SIZE=2>&gt;&gt;&gt; '%d' % 2147483647.0</FONT>
<BR><FONT SIZE=2>'2147483647'</FONT>
</P>

<P><FONT SIZE=2>Should %d accept also floats, and make the conversion? So there're two bugs:</FONT>
</P>

<P><FONT SIZE=2>- In the doc (it's not explicited that it should accept a other data types)</FONT>
</P>

<P><FONT SIZE=2>- In this behaviour difference:</FONT>
</P>

<P><FONT SIZE=2>&gt;&gt;&gt; '%d' % 2147483647.0</FONT>
<BR><FONT SIZE=2>'2147483647'</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; '%d' % 2147483648.0</FONT>
<BR><FONT SIZE=2>Traceback (most recent call last):</FONT>
<BR><FONT SIZE=2>...</FONT>
<BR><FONT SIZE=2>TypeError: int argument required</FONT>
</P>
<BR>

<P><FONT SIZE=2>I really don't know about opening a bug, because I don't know which to open, :p</FONT>
</P>

<P><FONT SIZE=2>.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Facundo</FONT>
</P>

</BODY>
</HTML>