Tools\Utility\Time::decimalToStandardTime PHP Method

decimalToStandardTime() public static method

Hours, minutes e.g. 9.5 => 9.3 with pad=2: 9.30
public static decimalToStandardTime ( integer $value, string | null $pad = null, string $decPoint = '.' ) : string
$value integer
$pad string | null
$decPoint string
return string
    public static function decimalToStandardTime($value, $pad = null, $decPoint = '.')
    {
        $base = (int) $value;
        $tmp = $value - $base;
        $tmp /= 1 / 60;
        $tmp /= 100;
        $value = $base + $tmp;
        if ($pad === null) {
            return $value;
        }
        return number_format($value, $pad, $decPoint, '');
    }

Usage Example

コード例 #1
0
ファイル: TimeTest.php プロジェクト: alescx/cakephp-tools
 /**
  * 9.50 => 9.30
  *
  * @return void
  */
 public function testDecimalStandard()
 {
     //echo $this->_header(__FUNCTION__);
     $value = '9.50';
     $is = $this->Time->decimalToStandardTime($value);
     $this->assertEquals('9.3', round($is, 2));
     $value = '9.5';
     $is = $this->Time->decimalToStandardTime($value);
     //pr($is);
     $this->assertEquals('9.3', $is);
     $is = $this->Time->decimalToStandardTime($value, 2);
     //pr($is);
     $this->assertEquals('9.30', $is);
     $is = $this->Time->decimalToStandardTime($value, 2, ':');
     //pr($is);
     $this->assertEquals('9:30', $is);
 }