the problem is found in a class i write,i found the 19.8851 past to the %f,only get 19.88509,is this because the float cant save too mush fractional part?
//
// main.m
// 0.6 the_float_not_corrert
//
// Created by Sen on 7/4/14.
// Copyright (c) 2014 SLboat. All rights reserved.
//
#import <Foundation/Foundation.h>
/**
* for get a float value from function
*
* @return a flaot value
*/
float getafloat(){
return 19.8851;
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSLog(@"const 19.8851 is %f",19.8851);
NSLog(@"19.8851 is %f",getafloat());
float byValue = 19.8851;
NSLog(@"19.8851 pass in value is %f",byValue);
}
return 0;
}
this is what i got
2014-07-04 09:42:07.508 0.6 the_float_not_corrert[11540:303] const 19.8851 is 19.885100
2014-07-04 09:42:07.510 0.6 the_float_not_corrert[11540:303] 19.8851 is 19.885099
2014-07-04 09:42:07.511 0.6 the_float_not_corrert[11540:303] 19.8851 pass in value is 19.885099
Program ended with exit code: 0