I create a NSNumberFormatter as below, set the max fraction digits to 2, and when I tried to format @"93.650000", it output like 93.65000000000001. I am confused, what's wrong with it?
Edit: My problem is, I don't what to output 93.65000000000001 as string, just 93.65 as string.
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
f.minimumFractionDigits = 0;
f.maximumFractionDigits = 2;
NSString *valueString;
for (NSString *valueStr in valueStrArray) {
valueString = valueStr;
if ((NSNull *)valueString == [NSNull null])
valueString = @"0";
NSNumber *value = [f numberFromString:valueString];
[vArray addObject:value];
}
original value string array:
<__NSCFArray 0x1742e8700>(
95.370000,
93.650000,
76.330000,
73.040000,
70.050000,
69,
66.510000,
57.540000,
53.760000,
<null>
)
formatted NSNumber array: (lldb) po vArray
<__NSArrayM 0x174c524b0>(
95.37,
93.65000000000001,
76.33,
73.04000000000001,
70.05,
69,
66.51000000000001,
57.54,
53.76,
0
)