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 7089503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:55:46+00:00 2026-05-28T07:55:46+00:00

I already know when a fraction is repeating decimals. Here is the function. public

  • 0

I already know when a fraction is repeating decimals. Here is the function.

public bool IsRepeatingDecimal
{
    get
    {
        if (Numerator % Denominator == 0)
            return false;

        var primes = MathAlgorithms.Primes(Denominator);

        foreach (int n in primes)
        {
            if (n != 2 && n != 5)
                return true;
        }

        return false;
    }
}

Now, I’m trying to get the repeated number. I’m checking this web site: http://en.wikipedia.org/wiki/Repeating_decimal

public decimal RepeatingDecimal()
{
    if (!IsRepeatingDecimal) throw new InvalidOperationException("The fraction is not producing repeating decimals");

    int digitsToTake;
    switch (Denominator)
    {
        case 3:
        case 9: digitsToTake = 1; break;
        case 11: digitsToTake = 2; break;
        case 13: digitsToTake = 6; break;
        default: digitsToTake = Denominator - 1; break;
    }

    return MathExtensions.TruncateAt((decimal)Numerator / Denominator, digitsToTake);
}

But I really realized, that some numbers has a partial decimal finite and later infinite. For example: 1/28

Do you know a better way to do this? Or an Algorithm?

  • 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-05-28T07:55:47+00:00Added an answer on May 28, 2026 at 7:55 am

    A very simple algorithm is this: implement long division. Record every intermediate division you do. As soon as you see a division identical to the one you’ve done before, you have what’s being repeated.

    Example: 7/13.

    1. 13 goes into   7 0 times with remainder  7; bring down a 0.
    2. 13 goes into  70 5 times with remainder  5; bring down a 0.
    3. 13 goes into  50 3 times with remainder 11; bring down a 0.
    4. 13 goes into 110 8 times with remainder  6; bring down a 0.
    5. 13 goes into  60 4 times with remainder  8; bring down a 0.
    6. 13 goes into  80 6 times with remainder  2; bring down a 0.
    7. 13 goes into  20 1 time  with remainder  7; bring down a 0.
    8. We have already seen 13/70 on line 2; so lines 2-7 have the repeating part
    

    The algorithm gives us 538461 as the repeating part. My calculator says 7/13 is 0.538461538. Looks right to me! All that remains are implementation details, or to find a better algorithm!

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

Sidebar

Related Questions

I already know that parse the wowarmoy's xml to get the data. But there
I saw here that: As you probably already know, relying on client-side validation alone
I already know how to, for instance, get tomorrow's date in a query in
I already know how to get my Activity as fullscreen on Android, now I
I already know that if you have n elements with equal heights=fill_parent, they get
I think I may already know the answer to this, but here goes. I
I already know how to: Load properties files into my Spring configuration using: <context:property-placeholder
I already know the obvious answer to this question: just download <insert favorite windows
I already know Java, Objective C, C#, and some Python. I want to be
I already know how to convert the non-utf8-encoded content of a file line by

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.