Converting string into decimal number in Python?

If you want the result as the nearest binary floating point number use float.

If you want the result as the nearest binary floating point number use float: result = float(x. Strip(' "')) for x in A1 If you want the result stored exactly use Decimal instead of float: from decimal import Decimal result = Decimal(x. Strip(' "')) for x in A1.

Tested this and realised it does not work because the strings have whitespace and extra quote marks in them. – Jake Jan 10 '11 at 5:46 Thanks, fixed. By the way, yours also needs correcting.

– Mark Byers Jan 10 '11 at 5:48 Tested it, works as is. – Jake Jan 10 '11 at 5:51.

You will need to use strip() because of the extra bits in the strings. A2 = float(x. Strip('"')) for x in A1.

4 You need to strip the extra space as well. – DSM Jan 10 '11 at 5:47 Tested it as is and it works. – Jake Jan 10 '11 at 5:50 2 Tested with a cut-and-paste of the OP's example?

It didn't work as is. – Mark Tolonen Jan 10 '11 at 6:47 @Mark, I've no idea what I did differently yesterday but it's not working now. Perhaps the question has been edited since I copied it.

– Jake Jan 10 '11 at 22:05.

Use the built in float() function in a list comprehension. A2 = float(v. Replace('"','').strip()) for v in A1.

A2 = float(x. Strip('"')) for x in A1 works, @Jake , but there are unnecessary 0s.

2 Does not work with OP's exact example. Zeroes aren't "unnecessary". Float can't represent all decimals exactly in binary.

But see Mark Byers answer. – Mark Tolonen Jan 10 '11 at 6:51 thanks for the heads up – tekknolagi Jan 10 '11 at 6:55.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions