Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to put decimal points in your calculator for mac only on Xcode.

I need help. I created an app for calculating division, multiplication, addition & Subtraction. But everytime I divide 5 / 4, I get 1 without a remainder. The calculator app in OS X has a remainder when I calculated the division problem. I searched on the internet for help, but all of them are iOS tutorials. HELP!!!!!!

iMac, OS X Mountain Lion (10.8.2), 4 GB RAM, 3.06 GHz Intel Core i3

Posted on Nov 23, 2012 2:33 PM

Reply
10 replies

Nov 24, 2012 7:30 AM in response to etresoft

Thanks, but what is the code for formatting them with "%f"? I tried "%.2f", but it asked me to fix it with "%2.d" instead. I using Xcode 4.5, and I need the code for formatting numbers in Mac Code, not iOS. Here's the code I wrote so far:


- (IBAction) getSum:(id)sender;

{

int addend1, addend2, sum;

addend1 = [mathField1 doubleValue];

addend2 = [mathField2 doubleValue];

sum = addend1 + addend2;

[mathAnssetDoubleValue:sum];

}


- (IBAction) getDiff:(id)sender;

{

int minu, subtrah, diff;

minu = [mathField1 doubleValue];

subtrah = [mathField2 doubleValue];

diff = minu - subtrah;

[mathAnssetDoubleValue:diff];

}


- (IBAction) getPro:(id)sender;

{

int mulcand, mulpiler, pro;

mulcand = [mathField1 doubleValue];

mulpiler = [mathField2 doubleValue];

pro = mulcand * mulpiler;

[mathAnssetDoubleValue:pro];

}


- (IBAction) getQuote:(id)sender;

{

int numer, denom, quote;

numer = [mathField1 doubleValue];

denom = [mathField2 doubleValue];

quote = numer / denom;

[mathAns setDoubleValue:quote];

}

Nov 24, 2012 9:44 AM in response to SFCXcode101

SFCXcode101 wrote:


Where is the integer math?


It is in your code. That is what you are doing. You are storing values in NSNumber objects, extracting double results via "doubleValue" and then storing the result into "int" data types.


I'm so confused. I need something simple...please don't give any advanced stuff. I'm a beginner at xcode, not an expert. I need the code only.


Sorry. I'm not going to give you the code. That is not the way to learn how to program. I have seen far too many such posts from people trying to learn how to program on their own, from a book. I have come to the conclusion that it simply isn't possible to do that. When you are first learning, you need a structured, group environment. I suggest taking a computer programming class at a local college or university. Once you get enough background, you will be able to pick up stuff on your own.


I'm not trying to discourage you, I'm just trying to point you in the most efficient path. I'm sure there will be classes starting in January. You can sign up for only a few hundred dollars. I'm sure people will try to suggest some online courses. You can try that and further delay your progress. I am no fan of the university culture, especially when it concerns computer science, but the the first couple of years of computer science classes are indispensable. You can't get that from a book and you can't get it from an online course.


What you are asking for isn't advanced knowledge, it is beginner knowledge.

Nov 24, 2012 9:56 AM in response to etresoft

OK. But someday I'll be able to get these decimals in the calculator so that 5 divided 4 doesn't say 1, but says 1.1 (1.3 in the Calculator app in OS X.) Here's the code once again:


- (IBAction) getSum:(id)sender;

{

int addend1, addend2, sum;

addend1 = [mathField1 doubleValue];

addend2 = [mathField2 doubleValue];

sum = addend1 + addend2;

[mathAnssetDoubleValue:sum];

}


- (IBAction) getDiff:(id)sender;

{

int minu, subtrah, diff;

minu = [mathField1 doubleValue];

subtrah = [mathField2 doubleValue];

diff = minu - subtrah;

[mathAnssetDoubleValue:diff];

}


- (IBAction) getPro:(id)sender;

{

int mulcand, mulpiler, pro;

mulcand = [mathField1 doubleValue];

mulpiler = [mathField2 doubleValue];

pro = mulcand * mulpiler;

[mathAnssetDoubleValue:pro];

}


- (IBAction) getQuote:(id)sender;

{

int numer, denom, quote;

numer = [mathField1 doubleValue];

denom = [mathField2 doubleValue];

quote = numer / denom;

[mathAns setDoubleValue:quote];

}


If this question has been answered, then I'll continue my Xcode development. If not, i'll have to throw my project in the trash. Leave me a suggestion.

Nov 24, 2012 10:45 AM in response to SFCXcode101

You didn't provide any context to the problem so I was trying to cover the most likely causes.


I saw your other posts too. I suggest you start your own questions instead of piggy backing onto someone else's year-old questions. That way, people who want to earn points can do so. Only the original poster of a question can award points. If you add a reply to an old thread owned by someone else, that is a good way to get your question ignored.


I've got plenty of points so this is an opportunity for other people to answer. If you post those new questions in the Developer forum, then the other developers here in Apple Support Communities will see them.


I really don't like supplying any ready-to-use code. I would rather give you tips to help you learn how to program on your own. I think that, in the long run, is more helpful than giving you code you don't understand.


Building a full-blown OS X application is not an easy job. I suggest starting with pure C code in the Terminal. That will be easier to learn how different types work and how the printf() function works. Both are critically important, fundamental concepts. It takes years to learn how to program. Don't be in a hurry.

How to put decimal points in your calculator for mac only on Xcode.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.