Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert string to a number

Posted on 2011-09-13
3
Medium Priority
?
243 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
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
HonorGod earned 1000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
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…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

876 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