HTH...function truncate ($num, $digits = 0) { //provide the real number, and the number of //digits right of the decimal you want to keep.

is the highest that you can do that does not return infinity) you probably won't notice any time difference.

Method to convert an arbitrary decimal number to its most reduced fraction form (so a string is returned, this method would probably be used for output formatting purposes.) There were other methods similar to this one on the page, but none did quite what I wanted.

It's maybe not the most elegant code, but it gets the job done. An iterative form of Euclid's algorithm is used to find the GCD.

Please note that shorter is not always better (meaning that really short faculty implementation above).

In my opinion, a clearer way to code this is, including a check for negative or non-integer values.

## Community Discussion