Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43574 > unrolled thread
| Started by | "pyth0n3r" <pyth0n3r@gmail.com> |
|---|---|
| First post | 2013-04-15 02:57 +0800 |
| Last post | 2013-04-19 15:04 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
howto remove the thousand separator "pyth0n3r" <pyth0n3r@gmail.com> - 2013-04-15 02:57 +0800
Re: howto remove the thousand separator Duncan Booth <duncan.booth@invalid.invalid> - 2013-04-19 15:04 +0000
| From | "pyth0n3r" <pyth0n3r@gmail.com> |
|---|---|
| Date | 2013-04-15 02:57 +0800 |
| Subject | howto remove the thousand separator |
| Message-ID | <mailman.595.1365965868.3114.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
Hi, I came across a problem that when i deal with int data with ',' as thousand separator, such as 12,916, i can not change it into int() or float(). How can i remove the comma in int data? Any reply will be appreciated!! Best, Chen
[toc] | [next] | [standalone]
| From | Duncan Booth <duncan.booth@invalid.invalid> |
|---|---|
| Date | 2013-04-19 15:04 +0000 |
| Message-ID | <XnsA1A7A3925AF01duncanbooth@127.0.0.1> |
| In reply to | #43574 |
"pyth0n3r" <pyth0n3r@gmail.com> wrote:
> I came across a problem that when i deal with int data with ',' as
> thousand separator, such as 12,916, i can not change it into int() or
> float(). How can i remove the comma in int data?
> Any reply will be appreciated!!
>
Parse it using the locale module, just be sure to set the correct locale
first:
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
'English_United Kingdom.1252'
>>> locale.atoi('1,000')
1000
>>> locale.atof('1,000')
1000.0
>>> locale.setlocale(locale.LC_ALL, 'French_France')
'French_France.1252'
>>> locale.atof('1,000')
1.0
--
Duncan Booth http://kupuguy.blogspot.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web