Lists and Decimal numbers
Wanderer
wanderer at dialup4less.com
Wed Mar 20 11:48:20 EDT 2013
On Wednesday, March 20, 2013 11:27:30 AM UTC-4, Ana DionĂsio wrote:
> So, I have this script that puts in a list every minute in 24 hours
>
>
>
> hour=[]
>
> i=0
>
> t=-(1.0/60.0)
>
> while i<24*60:
>
> i = i+1
>
> t = t+(1.0/60.0)
>
> hour.append([t])
>
>
>
> When it is doing the cicle it can have all the decimal numbers, but I need to print the result with only 4 decimal numbers
>
>
>
> How can I define the number of decimal numbers I want to print in this case? For example with 4 decimal numbers, it would print:
>
>
>
> 0.0000
>
> 0.0167
>
> 0.0333
>
> ...
>
>
>
> Can you help?
You can use round.
for t in hour:
print round(t,4)
More information about the Python-list
mailing list