Missing decimals in the code - some suggestions?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Apr 17 02:23:41 EDT 2013


On Tue, 16 Apr 2013 12:20:18 -0600, Ian Kelly wrote:

> This isn't a Python question.  If you take a look at the csv file that
> you download from Yahoo, you will see that it only contains 2 digits of
> precision.  There's no way to make Python print out 4 digits of
> precision when it is only provided with 2.

Pish posh! It's easy to add extra precision.


py> value = "2.57"
py> import random
py> n = random.randrange(0, 100)
py> value += "%2d" % n
py> print value
2.5791


On average, your numbers will only be off by five parts in a thousand. If 
the values represent dollars, that's half a cent. Who care about half a 
cent?



Adding-spurious-precision-for-fun-and-profit-ly y'rs,


-- 
Steven



More information about the Python-list mailing list