PHP Classes

File: hawkphp/floatObj.php

Recommend this page to a friend!
  Classes of tianfan   Hawk PHP Extended Object   hawkphp/floatObj.php   Download  
File: hawkphp/floatObj.php
Role: Class source
Content type: text/plain
Description: class for FLOAT type
Class: Hawk PHP Extended Object
Manipulating basic data types as objects
Author: By
Last change: description
Date: 2 years ago
Size: 1,318 bytes
 

Contents

Class file image Download
<?php

/**
 *@package extendObj
 *@author Tianfan<arrbo@hotmail.com>
 *@license Apache License 2.0
 *@varsion 0.0.2
 *@description this package is a part of hawkphp framework v2(haven't released)
 */

namespace hawkphp;

class
floatObj {

    private
$_float;

    const
CEIL = 0;
    const
FLOOR = 1;
    const
ROUND = 2;

    function
__construct(float $float) {
       
$this->_float = $float;
    }

    public function
getInt($type = SELF::FLOOR): int {
        switch (
$type) {
            case
SELF::FLOOR: {
                   
$return = \floor($this->_float);
                    break;
                }
            case
SELF::CEIL: {
                   
$return = \ceil($this->_float);
                    break;
                }
            case
SELF::ROUND: {
                   
$return = \round($this->_float);
                    break;
                }
        }
        return
$return;
    }

    public function
getDecimal(): int {
       
$tmp = \strval($this->_float);
       
$decimal = \explode(".", $tmp);
        return isset(
$decimal[1]) ? intval($decimal[1]) : 0;
    }

    public function
toFloat(): float {
        return
$this->_float;
    }

    public function
__toString() {
        return
strval($this->_float);
    }

}