(I posted this to ChennaiPy but this list is wider so I'm reposting it). Arulalan T <arulal...@gmail.com> writes:
> Dear All, > > I need one help. > > In python, I need to set the floating point precision as 2. > > I am getting the following output in python while adding two float nos. Often, you *need* to only display the result of your calculations with n decimal places. Is yours such a situation? If so, forget the number of decimal points during the computation and when printing format it as appropriate ("%.2f"). If you genuinely want to work without the floating point problem that you've indicated in your email, consider using the decimal module >>> import decimal >>> a = decimal.Decimal("79.73") >>> b = decimal.Decimal("0.5") >>> str(a + b) '80.23' [...] Can you tell us *why* this inaccuracy is hurting you? -- _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers