How to convert float to sortable integer in Python
Wolfgang Grafen
wolfgang.grafen at marconi.com
Tue Jan 16 07:17:25 EST 2007
shellon wrote:
> Hi all:
> I want to convert the float number to sortable integer, like the
> function float2rawInt() in java, but I don't know the internal
> expression of float, appreciate your help!
>
You should know you can sort mixed float/integer values in Python
>>> l=[3,2.3,1.45,2,5]
>>> l.sort()
>>> l
[1.45, 2, 2.2999999999999998, 3, 5]
to convert a float to int use the built-in int function:
>>> int(2.34)
2
Hope this helps
regards
Wolfgang
More information about the Python-list
mailing list