|
|
|
<?php
/*
Title: Temperature Conversion
Description: Convert celsius to fahrenheit and
fahrenheit to celsius.
Author: Murray Moffatt for A Web 4 U Designs
History:
2005-03-15 : Initial coding.
*/
function temp2celsius ($fahrenheit, $precision = 0) {
// Convert the supplied temperature in celsius to
// fahrenheit and return the value. Specify the required
// precision to round the converted value to.
// Returns FALSE on error.
if (!isset($fahrenheit)) return FALSE;
$precision = (integer)$precision;
$celsius = (float)(($fahrenheit - 32) / 1.8 );
return round($celsius, $precision);
}
function temp2fahrenheit ($celsius, $precision = 0) {
// Convert the supplied temperature in fahrenheit to
// celsius and return the value. Specify the required
// precision to round the converted value to.
// Returns FALSE on error.
if (!isset($celsius)) return FALSE;
$precision = (integer)$precision;
$fahrenheit = (float)(1.8 * $celsius) + 32;
return round($fahrenheit, $precision);
}
echo "<p>50F is " . temp2celsius(50) . "C</p>";
echo "<p>50C is " . temp2fahrenheit(50) . "F</p>";
?> |
|
| Reverse a given number Categories : PHP, Beginner Guides, Algorithms, Math. | | | Simple PHP Form Field Generator Categories : PHP, Beginner Guides, Form Processing, HTML and PHP | | | Script loading time Categories : PHP, Beginner Guides, Date Time | | | Diffusion-Limited Aggregation visualization Categories : PHP, Graphics, Algorithms, Math. | | | Different Call User Functions Categories : PHP, Functions, Beginner Guides | | | Local Time clock and Server time usign PHP and JavaScript Categories : PHP, Java Script, Date Time, Beginner Guides | | | Simple SOAP Example (with SoapClient) Categories : PHP, Web Services, SOAP, Beginner Guides | | | PHP based Contact email form with multiple recipients, text file based, supports departments. Categories : PHP, Email, Beginner Guides, Filesystem | | | How to Insert a Date Format Into MySQL from PHP Categories : PHP, Databases, MySQL, Date Time, Beginner Guides | | | Easy to use random number function that seeds with uniqid and allows a max value Categories : Math., PHP | | | decoct -- Decimal to octal Categories : PHP, PHP Functions, Math. | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Newbie Notes #10 - Generating drop downs Categories : PHP, MySQL, HTML, Beginner Guides, Databases | | | Creating a Language File Categories : PHP, Beginner Guides, Filesystem | | | 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 | |
|
|