this pseudocode is a total hack but you could use for loop to find acceptable answer
for den = 1 to maxDenominatorConsidered {
num = RoundOff(decimal * den)
residual = abs(decimal - num/den)
if residual < bestResidual {
bestResidual = residual
bestDenominator = den
}
}
then numerator = RoundOff(decimal * bestDenominator)
and bestResidual is error of fraction
also you should add a condition to leave for loop if you find a residual = 0
obviously runtime is linear wrt size of largest considered denominator
2007-09-10 09:39:42
·
answer #1
·
answered by Sugar Shane 3
·
0⤊
0⤋
you can only make a fraction if the decimal is repeating.
an example :
x = 0.091091091...
1000*x = 91.091091... = 91 + x
so
1000*x = 91 + x
or
999*x = 91 thus x = 91/999
this shouldnt be too difficult|to convert to a program.
isnt it something like ? :
length = number of repeating digits
( 10^length - 1 )/repeating_digits.
2007-09-10 09:19:56
·
answer #2
·
answered by gjmb1960 7
·
0⤊
0⤋
In arithmetic, an Egyptian fraction is a representation of an irreducible fraction as a sum of unit fractions, as e.g. 5/6 = a million/2 + a million/3. because of the fact the call shows, those representations have been used as some time past as historical Egypt, however the 1st revealed systematic approach for development such expansions is defined interior the Liber Abaci (1202) of Leonardo of Pisa (Fibonacci). that's mentioned as a grasping set of rules because of the fact at each and every step the set of rules chooses greedily the biggest conceivable unit fraction that is utilized in any representation of the relax fraction. Fibonacci certainly lists numerous diverse strategies for development Egyptian fraction representations (Sigler 2002, financial disaster II.7). He contains the grasping approach as a final motel for circumstances whilst numerous easier strategies fail; see Egyptian fraction for a greater particular itemizing of those strategies. As Salzer (1948) info, the grasping approach, and extensions of it for the approximation of irrational numbers, have been rediscovered numerous situations via cutting-area mathematicians, earliest and maximum extraordinarily via Sylvester (1880); see case in point Cahen (1891) and Spiess (1907). A heavily suitable strengthen approach that produces closer approximations at each and every step via allowing some unit fractions interior the sum to be unfavourable dates back to Lambert (1770). the upward thrust produced via this technique for a huge decision x is declared as the grasping Egyptian strengthen, Sylvester strengthen, or Fibonacci-Sylvester strengthen of x. whether, the term Fibonacci strengthen frequently refers, to no longer this technique, yet to representation of integers as sums of Fibonacci numbers.
2016-11-14 21:09:27
·
answer #3
·
answered by ? 4
·
0⤊
0⤋
#pragma warning( disable : 4244 ) // possible loss of data due to conversion
// Convert a Single to a string fraction of the
// form "integer numerator/denominator"
String* Utils::Form1::SingleToStringFraction(Single decimal, Int32 denominator)
{
// Input must be positive so save and restore the negative if necessary.
bool isneg = (Math::Sign(decimal) == -1) ? true : false;
if (isneg) decimal *= -1;
// obtain the decimal and units parts of the input number
Single remainder = Math::IEEERemainder(decimal, 1.0);
if (Math::Sign(remainder) == -1) remainder = 1 + remainder;
Int32 units = Convert::ToInt32(Math::Floor(decimal));
// compute the fractions numerator
Single divisor = Convert::ToSingle(1)/Convert::ToSingle(denominator);
Int32 numerator = Convert::ToInt32(Math::Round(remainder/divisor));
String* fraction;
// Handle an error or condition or reduce the fraction
// and convert to a string for the return.
if ((numerator > 0) && (numerator == denominator))
{
// than fraction is one full unit
units++;
fraction = S"";
}
else if (numerator == 0)
{
// as numerator is 0, no fraction
fraction = S"";
}
else
{
// reduce
while (numerator%2 == 0)
{
numerator /= 2;
denominator /= 2;
}
fraction = String::Format(" {0}/{1}",
numerator.ToString(), denominator.ToString());
}
// restore negativity
if (isneg) units *= -1;
#ifdef _DEBUG_CUT
String* rtnstr;
if (isneg) decimal *= -1;
rtnstr = String::Format("{0}{1}", units.ToString(), fraction);
Diagnostics::Trace::WriteLine(rtnstr, decimal.ToString());
#endif
return String::Format("{0}{1}", units.ToString(), fraction);
}
#pragma warning( default : 4244 )
2007-09-10 09:31:46
·
answer #4
·
answered by DanE 7
·
0⤊
0⤋
if a one place decimal, fraction is number / 10
if 2 place number, fraction is number /100
if 3 place number, fraction is number /1000
.......
2007-09-10 09:22:28
·
answer #5
·
answered by Anonymous
·
0⤊
0⤋