Convert string to a number

Posted on 2011-09-13
Last Modified: 2012-05-12
how to convert the string "1.217,000" to a number?

. stands for thousands and , for the decimal part...

Please provide a general answer for numbers formatted this way... thanks!
Question by:dfernan
  • 2
LVL 41

Accepted Solution

HonorGod earned 250 total points
ID: 36531799
Like this?
>>> s = '1.217,000'
>>> s.replace( '.', '' ).replace( ',', '.' )
>>> float( s.replace( '.', '' ).replace( ',', '.' ) )

Open in new window


Author Comment

ID: 36531829
thx! great!
LVL 41

Expert Comment

ID: 36531867
You are very welcome.

Thanks for the grade & points.

Good luck & have a great day.

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Python tuples 2 123
cannot use pip to install pandas or pandas_datareader 5 122
linux crontab output 3 73
Difference between List and Array in Python 5 67
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" " You can also get information on Python scripting language from the above mentioned we…
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question