#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    2
    Rep Power
    0

    Trying to remove a decimal from a number


    I am trying to remove the decimal from a number before I update a database. The strImplied is equal to 157.92 before the below line of code is executed. After the line of code is executed, the strImplied is equal to 15791. I need it to be 15792. Can anyone help out on this problem. Thanks.

    strImplied = str(int(float(strAmount) * 100))
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    12
    Code:
    int(round(float('157.92')*100))
    This is of course because there's no exact binary representation of 157.92. float('157.92') is in fact less than 157.92. This means that int() for your value will truncate it, giving you 15791.
    Last edited by percivall; May 26th, 2004 at 12:30 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    2
    Rep Power
    0

    It Works great


    Thanks for your help. It works great.

IMN logo majestic logo threadwatch logo seochat tools logo