Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:11:03+00:00 2026-06-14T13:11:03+00:00

I am trying to run my program and i am using double result =

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:11:04+00:00Added an answer on June 14, 2026 at 1:11 pm

    Lastly I found solution.All the explanation are right but “temporary” solution to this problem is with NSNumberFormatter.

    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    
    [formatter setAlwaysShowsDecimalSeparator:NO];
    [formatter setAllowsFloats:YES];
    [formatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    [formatter setMinimumFractionDigits:0];
    [formatter setMaximumFractionDigits:10]; //THIS IS IMPORTANT AS AFTER DECIMAL, DIGITS SHOULD BE LESS THAN 17 because there is difference of 6.12323e-17 
    
    double result = cos(90*M_PI/180);
    NSNumber *numberResult = [NSNumber numberWithDouble:result];
    
    [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
    NSLog(@"%@",[formatter stringFromNumber:number]); //Prints 0
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem when trying to run hello world program using android SDK.
I am trying to run a program and SOMETIMES I'm getting this error when
I'm trying to write a small baseball statistics program using data from retrosheet.org, but
Im trying to run a program with templates using operator < ,> methods, im
I am trying to run a simple program using a spring configuration file. In
When trying to run the following program code, this error occurred; Input string was
I'm trying to run a java program using the maven exec plugin using the
I am trying to run a simple SIP program using android 2.3 emulator. When
I'm using Netbeans, and trying to get a program Rational to run, so that
I am new to Java and am trying to run a program using Eclipse.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.