. */ /** * Provides static helper methods for converting values from one * format to another for display. * * These methods don't have state, they're only in a class for * purposes of namespacing. */ class ConversionHelpers { /** * Convert seconds to a time format string */ static public function ToTime($Value) { $Hour = floor($Value / 3600); $Minute = floor(($Value - $Hour * 3600) / 60); $Second = floor($Value - $Hour * 3600 - $Minute * 60); if(strlen($Hour) == 1) { $Hour = "0".$Hour; } if(strlen($Minute) == 1) { $Minute = "0".$Minute; } if(strlen($Second) == 1) { $Second = "0".$Second; } return ($Hour.":".$Minute.":".$Second); } /** * Convert to metric system */ static public function ToMetric($Value) { $Go = floor($Value / 1000000000); $Mo = floor(($Value - $Go * 1000000000) / 1000000); $Ko = floor(($Value - $Go * 1000000000 - $Mo * 1000000) / 1000); $o = floor($Value - $Go * 1000000000 - $Mo * 1000000 - $Ko * 1000); if($Go != 0) { return ($Go.".".$Mo."g"); } if($Mo != 0) { return ($Mo.".".$Ko."m"); } if($Ko != 0) { return ($Ko.".".$o)."k"; } return ($o); } /** * Convert to curency * * @param float $Value * @return string */ static public function ToCurrency($Value) { $Go = floor($Value / 1000000000); $Mo = floor(($Value - $Go * 1000000000) / 1000000); $Ko = floor(($Value - $Go * 1000000000 - $Mo * 1000000) / 1000); $o = floor($Value - $Go * 1000000000 - $Mo * 1000000 - $Ko * 1000); if(strlen($o) == 1) { $o = "00".$o; } if(strlen($o) == 2) { $o = "0".$o; } $ResultString = $o; if($Ko != 0) { $ResultString = $Ko.".".$ResultString; } if($Mo != 0) { $ResultString = $Mo.".".$ResultString; } if($Go != 0) { $ResultString = $Go.".".$ResultString; } return ($ResultString); } }