Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
September 28th, 2012, 04:51 PM
 amb1s1
Registered User

Join Date: Aug 2012
Posts: 25
Time spent in forums: 4 h 25 m 28 sec
Reputation 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
September 28th, 2012, 05:30 PM
 amb1s1
Registered User

Join Date: Aug 2012
Posts: 25
Time spent in forums: 4 h 25 m 28 sec
Reputation Power: 0
Quote:
 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)
```

#3
September 28th, 2012, 05:36 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,218
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 51 m 46 sec
Reputation Power: 455
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!

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > How to remove a comma out a thousand value