[Phphtmllib-devel] SF.net SVN: phphtmllib:[3170] trunk/open2300/lib/core/data/WXConversion.inc
Status: Beta
Brought to you by:
hemna
From: <he...@us...> - 2008-11-07 04:35:45
|
Revision: 3170 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3170&view=rev Author: hemna Date: 2008-11-07 04:35:42 +0000 (Fri, 07 Nov 2008) Log Message: ----------- added formats and mph to knots Modified Paths: -------------- trunk/open2300/lib/core/data/WXConversion.inc Modified: trunk/open2300/lib/core/data/WXConversion.inc =================================================================== --- trunk/open2300/lib/core/data/WXConversion.inc 2008-11-07 04:34:59 UTC (rev 3169) +++ trunk/open2300/lib/core/data/WXConversion.inc 2008-11-07 04:35:42 UTC (rev 3170) @@ -1,6 +1,14 @@ <?php class WXConversion { + + /** + * mulitply miles per hour by this + * to get knots. + * + * @var float + */ + public static $MPHKNOTS = 0.868976242; /** * This method converts Fahrenheit to @@ -9,8 +17,8 @@ * @param integer $temp * @return float */ - public static function fahrenheit_to_celsius($temp) { - return (float)sprintf("%.1f",(($temp - 32) / 1.8)); + public static function fahrenheit_to_celsius($temp, $format="%.1f") { + return (float)sprintf($format,(($temp - 32) / 1.8)); } /** @@ -19,8 +27,8 @@ * @param float $temp * @return float */ - public static function celsius_to_fahrenheit($temp) { - return (float)sprintf("%.1f",(($temp * 1.8) + 32)); + public static function celsius_to_fahrenheit($temp, $format="%.1f") { + return (float)sprintf($format,(($temp * 1.8) + 32)); } /** @@ -29,8 +37,8 @@ * @param float $temp * @return float */ - public static function celsius_to_kelvin($temp) { - return (float)sprintf("%.2f", ($temp + 273.15)); + public static function celsius_to_kelvin($temp, $format="%.2f") { + return (float)sprintf($format, ($temp + 273.15)); } /** @@ -39,8 +47,8 @@ * @param float $temp * @return float */ - public static function kelvin_to_celsius($temp) { - return (float)sprintf("%.2f", (273.15 - $temp)); + public static function kelvin_to_celsius($temp, $format="%.2f") { + return (float)sprintf($format, (273.15 - $temp)); } /** @@ -49,8 +57,8 @@ * @param float $temp * @return float */ - public static function fahrenheit_to_kelvin($temp) { - return self::celsius_to_kelvin(self::fahrenheit_to_celsius($temp)); + public static function fahrenheit_to_kelvin($temp, $format="%.1f") { + return self::celsius_to_kelvin(self::fahrenheit_to_celsius($temp, $format)); } /** @@ -59,8 +67,8 @@ * @package float $temp * @return float */ - public static function kelvin_to_fahrenheit($temp) { - return self::celsius_to_fahrenheit(self::kelvin_to_celsius($temp)); + public static function kelvin_to_fahrenheit($temp, $format="%.1f") { + return self::celsius_to_fahrenheit(self::kelvin_to_celsius($temp, $format)); } @@ -70,8 +78,8 @@ * @param float $pressure * @return float */ - public static function inchmercury_to_millibars($pressure) { - return (float)sprintf("%.2f", ($pressure * 33.8638)); + public static function inchmercury_to_millibars($pressure, $format="%.2f") { + return (float)sprintf($format, ($pressure * 33.8638)); } /** @@ -82,8 +90,8 @@ * * @param unknown_type $pressure */ - public static function millibars_to_inchmercury($pressure) { - return (float)sprintf("%.2f", ($pressure / 33.8638)); + public static function millibars_to_inchmercury($pressure, $format="%.2f") { + return (float)sprintf($format, ($pressure / 33.8638)); } /** @@ -92,8 +100,8 @@ * @param float $pressure * @return float */ - public static function inchmercury_to_atmospheres($pressure) { - return sprintf("%.2f", ($pressure * .0334211)); + public static function inchmercury_to_atmospheres($pressure, $format="%.2f") { + return sprintf($format, ($pressure * .0334211)); } /** @@ -102,13 +110,24 @@ * @param float $pressure * @return float */ - public static function atmospheres_to_inchmercury($pressure) { - return (float)sprintf("%.2f", ($pressure / .0334211)); + public static function atmospheres_to_inchmercury($pressure, $format="%.2f") { + return (float)sprintf($format, ($pressure / .0334211)); } + /** + * This method converts mph to knots + * + * @param float $mph + * @return float + */ + public static function mph_to_knots($mph) { + return (float)sprintf("%.2f", ($mph*WXConversion::$MPHKNOTS)); + } + + } ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |