1 | initial version |
Just use the usual pythonic way to format numbers. For instance:
myList = (pi, exp(16), sqrt(2019))
for x in myList:
print "%.2f" % x
The above gives:
3.14
8886110.52
44.93
(Using format
there are some problems, but the above works and it is enough for our purposes.)
So in our case, in a dialog with the sage interpreter:
sage: myList = sorted([ 2*cos(2*pi*j/5) for j in range(5) ])
sage: myList
[-1/2*sqrt(5) - 1/2,
-1/2*sqrt(5) - 1/2,
1/2*sqrt(5) - 1/2,
1/2*sqrt(5) - 1/2,
2]
sage: print [ '%.2f' % x for x in myList ]
['-1.62', '-1.62', '0.62', '0.62', '2.00']
sage: print ', '.join( [ '%.2f' % x for x in myList ] )
-1.62, -1.62, 0.62, 0.62, 2.00