# iOS接口数据解析问题

## 1、问题描述##

``````{
Environment = Both;
"Ground_indoor" = Finished;
"Ground_outdoor" = Finished;
"Max_Working_Height" = "9.800000000000001";
Name = "8m Battery Scissor Lift - Genie GS2632";
"Non_Marking_Tyres" = 1;
"Platform_Length" = "2.26";
"Platform_Type" = "Scissor Lift";
"Platform_Width" = "0.8100000000000001";
"Tax_Class" = E; Weight = 1956;
}
``````

## 2、问题解释##

Or if that is too much to read, let's simply put it this way - for example, let's take the value 0.81 as an example. The number cannot be accurately represented by a float and is rounded up to 0.8100000000000001 because an int value of 81 is represented by the binary value 1010001. In order to make the value 0.81 it would be accurate if you could take 81 x 10^-2 (= 81 / 10^2.) But that’s impossible because you must use the base 2 instead of 10. So the closest to 10^2 = 100 would be 128 = 2^7. The total number of bits you need is 9 : 6 for the value 81 (1010001) + 3 bits for the value 7 (111). Then the value 81 x 2^-7 is not seriously inaccurate. So to improve this inaccuracy, we could change the value 81 and 7 to something else. So the formula for your value would be X = A x 2^B where A and B are integer values positive or negative. The higher the numbers are the higher accuracy become. However as you know the number of bits to represent the values A and B are limited. For float you have a total number of 32. Double has 64 and Decimal has 128.

## 3、解决方案##

• 将接口数据以字符串的形式传给移动端，这种方法是最有效的。
``````NSNumberFormatter *fmt = [[NSNumberFormatter alloc] init];
[fmt setPositiveFormat:@"0.##"];