How to convert float to sortable integer in Python
John Machin
sjmachin at lexicon.net
Mon Apr 30 14:36:08 EDT 2007
On Apr 30, 11:23 pm, Larry Bates <larry.ba... at websafe.com> wrote:
> ire... at javeriana.edu.co wrote:
> > DEAR SIR,
> > I SAW YOUR INTERNET QUESTION AND I HAVE THE SAME TROUBLE.
> > CUOLD YOU HELP ME TO MAKE A FLOAT TO INTEGER CONVERTION?
> > DO YOU HAVE ANY EXEL FILE THAT CAN DO THAT?
> > REGARDS AND THANKS A LOT
>
> > IVAN REYES
>
> > ___________________________________
>
> > AVISO LEGAL: El presente correo electronico no representa la opinion o el consentimiento oficial de la PONTIFICIA UNIVERSIDAD JAVERIANA. Este mensaje es confidencial y puede contener informacion privilegiada la cual no puede ser usada ni divulgada a personas distintas de su destinatario. Esta prohibida la retencion, grabacion, utilizacion, aprovechamiento o divulgacion con cualquier proposito. Si por error recibe este mensaje, por favor destruya su contenido y avise a su remitente.
> > En este aviso legal se omiten intencionalmente las tildes.
>
> > Este mensaje ha sido revisado por un sistema antivirus, por lo que su contenido esta libre de virus.
> > This e-mail has been scanned by an antivirus system, so its contents is free of viruses.
>
> You have given us an ill defined problem.
>
> 1) If you want to convert float to int just use int() function.
> s=int(f)
>
> 2) If you want to keep some fractional part of the float multiply
> it by 10, 100, 1000, 10000, ... depending on how many digits of
> precision you wish to retain and then take int().
>
> s=int(f*10000)
>
> would retain 4 digits of precision and throw away the remainder.
>
> 3) You can sort on float just fine, so why do you need int()?
>
and:
(4) Who is the "dear sir" and what was his problem?
(5) How do you imagine that an Excel file could assist?
(6) Please consider giving your CapsLock key a squirt of WD-40 :-)
More information about the Python-list
mailing list