How to convert float to sortable integer in Python

Discussion in 'Python' started by ireyes@javeriana.edu.co, Apr 28, 2007.

  1. Guest

    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.
    , Apr 28, 2007
    #1
    1. Advertising

  2. Larry Bates Guest

    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()?

    -Larry
    Larry Bates, Apr 30, 2007
    #2
    1. Advertising

  3. John Machin Guest

    On Apr 30, 11:23 pm, Larry Bates <> wrote:
    > 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 :)
    John Machin, Apr 30, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy
    Replies:
    7
    Views:
    6,256
    Roedy Green
    May 10, 2004
  2. bd
    Replies:
    0
    Views:
    624
  3. shellon
    Replies:
    7
    Views:
    3,116
    Gabriel Genellina
    Jan 17, 2007
  4. Replies:
    11
    Views:
    618
    Antoon Pardon
    Mar 8, 2007
  5. Carsten Fuchs
    Replies:
    45
    Views:
    1,540
    James Kanze
    Oct 8, 2009
Loading...

Share This Page