/
Floating.php
95 lines (74 loc) · 2.09 KB
/
Floating.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/base/blob/master/LICENSE
*/
namespace Quid\Base;
// floating
// class with static methods to work with floating numbers
final class Floating extends Root
{
// config
protected static array $config = [];
// typecast
// typecasts des valeurs float par référence
final public static function typecast(&...$values):void
{
foreach ($values as &$value)
{
$value = (float) $value;
}
}
// cast
// cast une valeur en float, utilise num::cast
final public static function cast($value,bool $commaToDecimal=true):?float
{
$float = Num::castMore($value,$commaToDecimal);
return (is_numeric($float))? (float) $float:null;
}
// is
// retourne vrai si la valeur est float
final public static function is($value):bool
{
return is_float($value);
}
// isEmpty
// retourne vrai si la valeur est float et vide
final public static function isEmpty($value):bool
{
return is_float($value) && empty($value);
}
// isNotEmpty
// retourne vrai si la valeur est float et non vide
final public static function isNotEmpty($value):bool
{
return is_float($value) && !empty($value);
}
// isCast
// vérifie que la valeur est numérique et float après cast
final public static function isCast($value):bool
{
$return = false;
if(is_numeric($value))
{
Num::typecast($value);
$return = (self::is($value));
}
return $return;
}
// isCastNotEmpty
// vérifie que la valeur est numérique et un après après cast et n'est pas 0
final public static function isCastNotEmpty($value):bool
{
$return = false;
if(is_numeric($value))
{
Num::typecast($value);
$return = (self::isNotEmpty($value));
}
return $return;
}
}
?>