Solved

Convert string to a number

Posted on 2011-09-13
3
239 Views
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!
0
Comment
Question by:dfernan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 41

Accepted Solution

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

Open in new window

0
 

Author Comment

by:dfernan
ID: 36531829
thx! great!
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36531867
You are very welcome.

Thanks for the grade & points.

Good luck & have a great day.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
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 lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

726 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