Convert "1.0E-4" from NSString to double

Alexandru Circus picture Alexandru Circus · Jan 13, 2011 · Viewed 7.1k times · Source

I want to get the double value from "1.04E-4" NSString, but I didn't manage yet how to do it. I tried the following:

1.

NSString* str = @"1.0E-4";
double value = [str doubleValue];  //returns 0.0001

2.

NSString* str = @"1.0E-4";
double value;
NSScanner* scanner = [NSScanner scannerWithString:str];
[scanner scanDouble:&value];
//0.0001 again

Instead of value = 1.0E-4, I get 0.0001

Could someone help me with this?

Appreciate,

Alex.

Answer

Alexsander Akers picture Alexsander Akers · Jan 13, 2011

For the record, 1.0E-4 = 0.0001.