Passed
Push — v6 ( 6aa863...3dc3c0 )
by 光春
02:30
created

Decimals   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 8
c 1
b 0
f 0
dl 0
loc 54
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A intval() 0 3 1
A ceil() 0 3 1
A floor() 0 3 1
A round() 0 3 1
A judge() 0 7 2
1
<?php
2
3
// +----------------------------------------------------------------------
4
// | ThinkLibrary 6.0 for ThinkPhP 6.0
5
// +----------------------------------------------------------------------
6
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
7
// +----------------------------------------------------------------------
8
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
9
// +----------------------------------------------------------------------
10
// | 开源协议 ( https://mit-license.org )
11
// +----------------------------------------------------------------------
12
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
13
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
14
// | gitlab 仓库地址 :https://gitlab.com/liguangchun/thinklibrary
15
// | weixin 仓库地址 :https://git.weixin.qq.com/liguangchun/ThinkLibrary
16
// | huaweicloud 仓库地址 :https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git
17
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
18
// +----------------------------------------------------------------------
19
20
declare (strict_types=1);
21
22
namespace DtApp\ThinkLibrary\helper;
23
24
/**
25
 * 小数管理类
26
 * @mixin  Decimals
27
 * @package DtApp\ThinkLibrary\helper
28
 */
29
class Decimals
30
{
31
    /**
32
     * 直接取整,舍弃小数保留整数
33
     * @param $num
34
     * @return int
35
     */
36
    public function intval($num): int
37
    {
38
        return (int)$num;
39
    }
40
41
    /**
42
     * 四舍五入取整
43
     * @param $num
44
     * @return float
45
     */
46
    public function round($num)
47
    {
48
        return round($num);
49
    }
50
51
    /**
52
     * 有小数,就在整数的基础上加一
53
     * @param $num
54
     * @return false|float
55
     */
56
    public function ceil($num)
57
    {
58
        return ceil($num);
59
    }
60
61
    /**
62
     * 有小数,就取整数位
63
     * @param $num
64
     * @return false|float
65
     */
66
    public function floor($num)
67
    {
68
        return floor($num);
69
    }
70
71
    /**
72
     * 判断是不是小数
73
     * @param $num
74
     * @return bool
75
     */
76
    public function judge($num): bool
77
    {
78
        if (is_int($num)) {
79
            return false;
80
        }
81
82
        return true;
83
    }
84
}
85