2010/8/24 Roshan George <[email protected]>

> On Tue, 2010-08-24 at 16:04 +0530, Arulalan T wrote:
> >
> > I am getting the following output in python while adding two float nos.
> >
> > >>>a=79.73
> > >>>b=0.5
> > >>> a+b
> > 80.230000000000004
> >
> > I need exactly 2 precision point in this float value. i.e. 80.23
>
> That's a limitation of binary floating point. The number 80.23 cannot be
> represented exactly. Use the decimal module if you want exact numbers:
> <http://docs.python.org/library/decimal.html>. For more information look
> at the Python Docs on floating point:
> <http://docs.python.org/tutorial/floatingpoint.html>.
>
> As you'll see there, Python 3.1 will print the result in the way you
> want, but if you want more accurate arithmetic, multiply all your
> numbers by 100 and use integers instead or use the decimal module.
>
>

Yes, we can do this multiply by 100 way.
By this way I can handle 80 and 23 as two separate integers.
But when I want make it as float
>>>80+0.23
 80.230000000000004

again it will be come same floating value.
so I cant use this way.




--
> Roshan George
>
> _______________________________________________
> ILUGC Mailing List:
> http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
>



-- 
Regards,
Arulalan.T

Kanchi Linux User Group Rocks !
http://kanchilug.wordpress.com

My Experiments In Linux are here
http://tuxcoder.wordpress.com
_______________________________________________
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc

Reply via email to