Algorithmically Finding the LCD (or decimal to fractions)

  • Context: Undergrad 
  • Thread starter Thread starter k_squared
  • Start date Start date
  • Tags Tags
    Fractions Lcd
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 2K views
k_squared
Messages
62
Reaction score
0
I wrote a program to convert decimals into fractions. It basically puts the decimal over the proper power of ten, and simplifies (at least, for nonreapeating fractions.) However, it uses a brute force method to find the LCD, and as a matter of aesthetics, I never like brute force. Does anyone know of some more efficient ways do do that?
 
Mathematics news on Phys.org
Just divide by two until it won't go in any longer, then divide by 5 until it won't go in any longer.

0.88 -> 88/100 = 44/50 = 22/25. Two won't go into the denominator anymore, and 5 won't go into the numerator, so you're done.

This let's you simplify 0.00000000000001048576 in twenty steps instead of a million.
 
Awesome.
Neat how it works like that - I wish I had a knack for seeing that kinda thing off the top of my head.
 
k_squared said:
Awesome.
Neat how it works like that - I wish I had a knack for seeing that kinda thing off the top of my head.

It's just the fundamental theorem of arithmetic (aka "uniqueness of prime factorization") at work. The only prime factors of any positive power of ten (eg 10 100 1000 etc) are 2 and 5.
 
CRGreathouse said:
This let's you simplify 0.00000000000001048576 in twenty steps instead of a million.

The Euclidean algorithm will find this is ONE step, since 1048576 divides 10^20. The reduced fraction is 1/95367431640625.