I am trying to run my program and i am using
double result = cos(90*M_PI/180);
NSLog("Cos 90 value %g",result); //Prints 6.12323e-17
But when i run this
NSLog("Cos 90 value %f",cos(90*M_PI/180)); //Prints 0
I want to get value of cos90 in result(double) which should be 0.I know thats floating point airthmetic issue.But how to solve it.Is there any way to do it?
Thanks
Lastly I found solution.All the explanation are right but “temporary” solution to this problem is with
NSNumberFormatter.It’s a temporary solution.You can also prints value of cos 90 with %f but it will also prints unwanted six 0 after decimal.