[Tutor] floats

Nitin Pawar nitinpawar432 at gmail.com
Fri Dec 3 19:56:13 CET 2010


you have two options
1) either type cast like float_b = float(etcetc)
2) use round method which available inbuilt

On Sat, Dec 4, 2010 at 12:22 AM, Christopher Spears
<cspears2002 at yahoo.com>wrote:

>
> I have a float variable that is very long.
>
> >>> float_a = 1.16667
>
> 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.
>
> >>> float_a = 1.16667
> >>> print "%.2f" % float_a
> 1.17
>
> I tried the following:
>
> >>> float_b = "%.2f" % float_a
> >>> float_b
> '1.17'
> >>> type(float_b)
> <type 'str'>
>
> This doesn't work because it yields a string.
>
> Any suggestions?
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Nitin Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101204/610e60ef/attachment.html>


More information about the Tutor mailing list