WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Decimal to Fraction - A function that converts numbers with decimal remainders to numbers with fractional remainders.
Categories : PHP, Math. Click here to Update Your Picture
Zak Greant
Date : Feb 14th 2001
Grade : Be the 1st to grade this Code Example
Viewed : 4391
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Zak Greant
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?
function decimal_to_fraction ($number)
{
list ($whole, $numerator) = explode ('.', $number);

$denominator = 1 . str_repeat (0, strlen ($numerator));

$GCD = GCD ($numerator, $denominator);

$numerator /= $GCD;
$denominator /= $GCD;

return sprintf ('%d <sup>%d</sup>/<sub>%d</sub>',
$whole, $numerator, $denominator);
}

function GCD ($a, $b)
{
while ( $b != 0)
{
$remainder = $a % $b;
$a = $b;
$b = $remainder;
}
return abs ($a);
}

/*
DESCRIPTION
============================================================
Decimal_to_Fraction:
A simple function that converts numbers with decimal
remainders to numbers with fractional remainders.

Includes a function to find the greatest common denominator.
============================================================

CREDITS
============================================================
Author: J. A. Greant ( zak@nucleus.com )
Version 1: June 9, 2000
============================================================

NOTICES
============================================================
If you:
Modify this code and want to share your changes :)
Find a bug
Have other questions or comments

Please write:
Zak Greant (zak@nucleus.com)
============================================================

USAGE EXAMPLES
============================================================
print Decimal_to_Fraction (1.2); // Should output 1 1/5

============================================================

COPYRIGHT
============================================================
Copyright (c) 2000 J. A. Greant ( zak@nucleus.com )
All rights reserved.

This function is free software; you can redistribute it
and/or modify it under the terms of the GNU Lesser General
Public License as published by the Free Software Foundation;
either version 2.1 of the License, or (at your option) any
later version.

This function is distributed in the hope that it will be
useful,but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General
Public License along with this function; if not, write to
the:
Free Software Foundation, Inc.
59 Temple Place, Suite 330
Boston, MA
02111-1307 USA
http://www.gnu.org/
============================================================
*/
?>



Library of math functions to expand the functionality of PHP3. Version 1.2.1 fixes a major problem with the gcd function.
Categories : Algorithms, PHP, Math.
Prime number finder (Sieve of Erastothenes)
Categories : PHP, Algorithms, Math.
Math operations on big numbers
Categories : PHP, Math.
Latitude-Longitude to Miles
Categories : PHP, Utilities, Math.
Diffusion-Limited Aggregation visualization
Categories : PHP, Graphics, Algorithms, Math.
Reverse a given number
Categories : PHP, Beginner Guides, Algorithms, Math.
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
Easy to use random number function that seeds with uniqid and allows a max value
Categories : Math., PHP
Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other?
Categories : PHP, Math., Arrays
decoct -- Decimal to octal
Categories : PHP, PHP Functions, Math.
Show the steps for converting a number from a given base to base 10. Shows the steps involved in converting a number from a given base to base 10.
Categories : PHP, Math., Algorithms
Temperature Conversion
Categories : PHP, Math., Beginner Guides
Calculator for Baroque Violin strings
Categories : Math., PHP, Strings
How to judge if an integer is odd or is even in Php3?
Categories : Math., PHP, Algorithms
Arbitrary Precision Math using BCMATH routines
Categories : PHP, Math., BC math