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

    Join Date
    Aug 2012
    Posts
    25
    Rep Power
    0

    How to remove a comma out a thousand value


    I'm creating this webapp for my cousin. He own a trunking business so he want his website to give quote base on miles. So I got almost everything on the backend working. Now I'm encounter an issue. Since to give the quote and I need to use calculation, I having issues with distance over 1,000 miles because python can calculate that. How can I remove the comma from a 1,00 value.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    25
    Rep Power
    0
    Originally Posted by amb1s1
    I'm creating this webapp for my cousin. He own a trunking business so he want his website to give quote base on miles. So I got almost everything on the backend working. Now I'm encounter an issue. Since to give the quote and I need to use calculation, I having issues with distance over 1,000 miles because python can calculate that. How can I remove the comma from a 1,00 value.
    I found a way

    Code:
    comma ="," in result2
    if comma == True:
                result2=result2.replace(",", "")
                result2=float(result2)
                
    else:
                result2=float(result2)
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Once you've isolated the number:
    Code:
    >>> s = '1,000'
    >>> float(''.join(s.split(',')))
    1000.0
    >>>
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo