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

  • Home
  • SEARCH
  • 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 8013271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:35:40+00:00 2026-06-04T19:35:40+00:00

i am new to objective C and I started to learn the basics in

  • 0

i am new to objective C and I started to learn the basics in iOS development.

How can I easily calculate with fractions in Objective C?

Example 1: 1/8000 * 60

Example 2: 1/640 / 1/400

I need to have the result (if its < 1) as a fraction, too.

  • 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-04T19:35:41+00:00Added an answer on June 4, 2026 at 7:35 pm

    I think I would implement a new class, say Fraction which has two properties, the numerator and denominator. I would then implement four (or more if necessary) of the following functions:

    - (Fraction*) add:(Fraction*)operand;
    - (Fraction*) subtract:(Fraction*)operand;
    - (Fraction*) multiply:(Fraction*)operand;
    - (Fraction*) divide:(Fraction*)operand;
    - (Fraction*) invert;
    + (Fraction*) fractionByAdding:(Fraction*)op1 to:(Fraction*)op2;
    + (Fraction*) fractionBySubtracting:(Fraction*)op1 from:(Fraction*)op2;
    + (Fraction*) fractionByMultiplying:(Fraction*)op1 with:(Fraction*)op2;
    + (Fraction*) fractionByDuviding:(Fraction*)op1 by:(Fraction*)op2;
    + (Fraction*) fractionByInverting:(Fraction*)operand;
    

    In these methods, do the usual arithmetic you learned in school. Remember to simplify if both numerator and denominator has common divisors.

    EDIT: Example implementation for one of these functions:

    - (Fraction*) add:(Fraction*)operand {
        return [Fraction fractionByAdding:self to:operand];
    }
    
    + (Fraction*) fractionByAdding:(Fraction*)op1 to:(Fraction*)op2 {
        int num = (op1.numerator * op2.denominator) + (op2.numerator * op1.denominator);
        int denom = op1.denominator * op2.denominator;
        return [[Fraction alloc] initWithNumerator:num andDenominator:denom];
    }
    

    Optionally you could add a reduce or simplify method and possibly an allowReducible property and an isIrreducible method. You could also implement isEqual and compareTo methods. A description should just print “a/b” as an NSString.

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

Sidebar

Related Questions

New to Objective-C and iOS development, would love a hand here! I have written
I'm new to iPhone/Objective-C development. I jumped the gun and started reading and implementing
I am new to objective-c and started iphone application development. I have noticed the
I'm new to Objective-C and development on Apple's platforms, but hopefully I can frame
First, I'm new to iOS and Objective-C programming (I started a month ago). I'm
I am new to iOS development. I've recently stumbled upon the new objective-c collection-literals
I'm totally new to objective c and iphone development. I'm trying to create an
I'm pretty new to objective C started a few days ago... I want to
i'm new here, i'm new in iphone development, i'm new in Objective-c and i'm
I'm practically new to Objective C and iOS Dev and I need to make

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.