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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:13:20+00:00 2026-05-10T15:13:20+00:00

Let’s say we have 0.33 , we need to output 1/3 . If we

  • 0

Let’s say we have 0.33, we need to output 1/3.
If we have 0.4, we need to output 2/5.

The idea is to make it human-readable to make the user understand ‘x parts out of y‘ as a better way of understanding data.

I know that percentages is a good substitute but I was wondering if there was a simple way to do this?

  • 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. 2026-05-10T15:13:21+00:00Added an answer on May 10, 2026 at 3:13 pm

    I have found David Eppstein’s find rational approximation to given real number C code to be exactly what you are asking for. Its based on the theory of continued fractions and very fast and fairly compact.

    I have used versions of this customized for specific numerator and denominator limits.

    /* ** find rational approximation to given real number ** David Eppstein / UC Irvine / 8 Aug 1993 ** ** With corrections from Arno Formella, May 2008 ** ** usage: a.out r d **   r is real number to approx **   d is the maximum denominator allowed ** ** based on the theory of continued fractions ** if x = a1 + 1/(a2 + 1/(a3 + 1/(a4 + ...))) ** then best approximation is found by truncating this series ** (with some adjustments in the last term). ** ** Note the fraction can be recovered as the first column of the matrix **  ( a1 1 ) ( a2 1 ) ( a3 1 ) ... **  ( 1  0 ) ( 1  0 ) ( 1  0 ) ** Instead of keeping the sequence of continued fraction terms, ** we just keep the last partial product of these matrices. */  #include <stdio.h>  main(ac, av) int ac; char ** av; {     double atof();     int atoi();     void exit();      long m[2][2];     double x, startx;     long maxden;     long ai;      /* read command line arguments */     if (ac != 3) {         fprintf(stderr, "usage: %s r d\n",av[0]);  // AF: argument missing         exit(1);     }     startx = x = atof(av[1]);     maxden = atoi(av[2]);      /* initialize matrix */     m[0][0] = m[1][1] = 1;     m[0][1] = m[1][0] = 0;      /* loop finding terms until denom gets too big */     while (m[1][0] *  ( ai = (long)x ) + m[1][1] <= maxden) {         long t;         t = m[0][0] * ai + m[0][1];         m[0][1] = m[0][0];         m[0][0] = t;         t = m[1][0] * ai + m[1][1];         m[1][1] = m[1][0];         m[1][0] = t;         if(x==(double)ai) break;     // AF: division by zero         x = 1/(x - (double) ai);         if(x>(double)0x7FFFFFFF) break;  // AF: representation failure     }       /* now remaining x is between 0 and 1/ai */     /* approx as either 0 or 1/m where m is max that will fit in maxden */     /* first try zero */     printf("%ld/%ld, error = %e\n", m[0][0], m[1][0],            startx - ((double) m[0][0] / (double) m[1][0]));      /* now try other possibility */     ai = (maxden - m[1][1]) / m[1][0];     m[0][0] = m[0][0] * ai + m[0][1];     m[1][0] = m[1][0] * ai + m[1][1];     printf("%ld/%ld, error = %e\n", m[0][0], m[1][0],            startx - ((double) m[0][0] / (double) m[1][0])); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have a method in java, which looks up a user in
Let's say I have thousands of users and I want to make the passwords
Let's say I have an facebook application running using the JS SDK. First user
Let me explain best with an example. Say you have node class that can
Let's say I have a table with a Color column. Color can have various
Let's say that I have a SQLite database that I create in a separate
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and

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.