you have two options <div>1) either type cast like float_b = float(etcetc)</div><div>2) use round method which available inbuilt <br><br><div class="gmail_quote">On Sat, Dec 4, 2010 at 12:22 AM, Christopher Spears <span dir="ltr"><<a href="mailto:cspears2002@yahoo.com">cspears2002@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
I have a float variable that is very long.<br>
<br>
>>> float_a = 1.16667<br>
<br>
However, I want to pass the value of float_a to float_b, but I want the float to be accurate to two decimal points.<br>
<br>
>>> float_a = 1.16667<br>
>>> print "%.2f" % float_a<br>
1.17<br>
<br>
I tried the following:<br>
<br>
>>> float_b = "%.2f" % float_a<br>
>>> float_b<br>
'1.17'<br>
>>> type(float_b)<br>
<type 'str'><br>
<br>
This doesn't work because it yields a string.<br>
<br>
Any suggestions?<br>
_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Nitin Pawar<br><br>
</div>