October 2004
Intermediate to advanced
336 pages
6h 27m
English
This function takes two parameters, the numerator and denominator of a fraction, and determines the repeating part of the fraction (if one exists).
The logic is simple: After removing any part of the result that is a whole number, it begins dividing the denominator into the numerator and tracking the remainder after each digit. If the remainder becomes 0, then the function is done. Otherwise, when a remainder repeats, it has found the repeating part.
Because Perl treats all numbers as floating-point numbers, the easiest way to truncate a number to its integer part is to sprintf() it into a string using the "%d" ...
Read now
Unlock full access