There doesn't seem to be any direct way to achieve this. <div><br></div><div>Maybe you can do something like this: </div><div><br></div><div>import math</div><div><br></div><div>x = 3.05</div><div><br></div><div>if math.modf(x)[0] != 0.0: print x</div>
<div><br></div><div><br></div><div>Cheers,</div><div>-Kamlesh</div><div><br></div><div><br></div><div><br></div><div> <br><div class="gmail_quote">On Mon, Oct 15, 2012 at 5:59 PM, Chris Rebert <span dir="ltr"><<a href="mailto:clp2@rebertia.com" target="_blank">clp2@rebertia.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Mon, Oct 15, 2012 at 5:12 AM, Neal Becker <<a href="mailto:ndbecker2@gmail.com">ndbecker2@gmail.com</a>> wrote:<br>
> Is there a way to specify to format I want a floating point written with no more<br>
> than e.g., 2 digits after the decimal? I tried {:.2f}, but then I get all<br>
> floats written with 2 digits, even if they are 0:<br>
><br>
> 2.35 << yes, that's what I want<br>
> 2.00 << no, I want just 2 or 2.<br>
<br>
</div>Not that I can find. Seems you'll have to implement it yourself.<br>
<br>
<br>
In the event that your project uses Django, there happens to be a<br>
template tag for this (pass it -2 in your case):<br>
<a href="https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#floatformat" target="_blank">https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#floatformat</a><br>
<br>
Cheers,<br>
Chris<br>
<span class="HOEnZb"><font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Faith waiting in the heart of a seed promises a miracle of life which it can not prove! <br>-Ravindranath Tagore<br>
</div>