class_mcNumber.inc.php
1.1 KB
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
<?php
/**
* @copyright (c) 2014, netz.coop eG
*/
class mcNumber {
public static function round2($param_number) {
return round($param_number, 2);
}
public static function form2($param_number) {
return number_format(round($param_number, 2), 2, ",", ".");
}
public static function form5($param_number) {
return number_format(round($param_number, 5), 2, ",", ".");
}
public static function transformStringToFloat($param_string) {
// D::ulli($param_string);
if(strpos($param_string, ',')!==false) {
$param_string = str_replace(',', '.', $param_string);
}
// D::ulli('return '.$price);
return $param_string;
}
public static function transformProcentToInt($param_procent) {
if(strpos($param_procent, '%')!==false) {
$percent = str_replace('%', '', $param_procent);
$percent = trim($percent);
} else if(strpos($param_procent, '0,')!==false) {
$percent = 100*mcNumber::transformStringToFloat($param_procent);
} else {
$percent = $param_procent;
}
// D::li('transformProcentToInt '.$param_procent.' => '.$percent);
return trim($percent);
}
}
?>