Es kommen aber ganze Zahlen heraus:
Code: Alles auswählen
>>> x = 1/2
>>> x
0
>>> x = 3/2
>>> x
1
Code: Alles auswählen
>>> x = 1/2
>>> x
0
>>> x = 3/2
>>> x
1
Code: Alles auswählen
>>> x = round(1.0/2,2)
>>> x
0.5
>>> x = round(3.0/2,2)
>>> x
1.5
>>> x = round(1.0/3,2)
>>> x
0.33
>>> x = round(1.0/3,4)
>>> x
0.3333
>>>
Code: Alles auswählen
In [16]: [round(0.5 + i) for i in range(10)]
Out[16]: [0, 2, 2, 4, 4, 6, 6, 8, 8, 10]
Code: Alles auswählen
In [17]: '%.50f' % 0.1
Out[17]: '0.10000000000000000555111512312578270211815834045410'
In [18]: '%.50f' % round(0.1, 1)
Out[18]: '0.10000000000000000555111512312578270211815834045410'