Recently, in the process of doing the project, I stumbled across a problem, that is, the conversion of string and floating-point types. In the past, it was through [NSString stringwithformat:@ "%d", Goodcount] this way, and didn't care too much. Customer feedback in a project today after entering a very long number, the data display of the floating-point type is inconsistent with the input. After repeated testing, it was found that float type can only support to 8-bit, that is to say 12345678 such a number through the float type is no problem, but if more than eight bit after nsstring *[email protected] " 1234567890 "; NSLog (@ "Data type%.2f,%.2f", [Temstr floatvalue],[temstr doublevalue]); Print output data type 1234567936.00, 1234567890.00. The original float type has a maximum capacity of 8 bits, whereas a double type has a capacity of 16 bits, so the conversion of strings and floating-point types is best used in the project development process with a double type. However, a double type is distorted if it exceeds 16 bits (nsstring *[email protected] "123456789012345678"; NSLog (@ "Data type%.2f,%.2f", [Temstr floatvalue],[temstr doublevalue]); Print output data type 123456790519087104.00,123456789012345680.00), but it's enough.
Resolution of string to float type distortion in iOS