4 require_once
'Services/Math/interfaces/interface.ilMathAdapter.php';
20 if (is_numeric($number)) {
21 $scale = (int) $scale;
23 $number = $this->
exp2dec($number);
24 if (strpos($number,
'.') ===
false) {
25 $number_of_decimals = 0;
27 $number_of_decimals = strlen(substr($number, strpos($number,
'.') + 1));
30 if ($number_of_decimals > 0 && $number_of_decimals < $scale) {
31 $number = str_pad($number, $scale - $number_of_decimals,
'0');
32 } elseif ($number_of_decimals > $scale) {
33 $number = substr($number, 0, -($number_of_decimals - $scale));
43 public function round($value, $precision = 0)
45 return number_format($value, $precision,
'.',
'');
51 public function equals($left_operand, $right_operand, $scale = null)
53 return $this->
comp($left_operand, $right_operand, $scale) === 0;
64 if (null === $number) {
68 $number = str_replace(
' ',
'', $number);
69 $number = $this->
exp2dec($number);
70 $locale_info = localeconv();
72 if ($locale_info[
'decimal_point'] !=
'.') {
74 $number_of_decimals = (int) ini_get(
'precision') - (int) floor(log10(abs($number)));
75 if (0 > $number_of_decimals) {
76 $number *=
pow(10, $number_of_decimals);
77 $append = str_repeat(
'0', -$number_of_decimals);
78 $number_of_decimals = 0;
81 return number_format($number, $number_of_decimals,
'.',
'') . $append;
96 $original = $float_str;
97 $float_str = (
string) ((
float) ($float_str));
98 $float_str = str_replace(
",",
".", $float_str);
101 if (($pos = strpos(strtolower($float_str),
'e')) !==
false) {
103 $exp = substr($float_str, $pos+1);
104 $num = substr($float_str, 0, $pos);
107 if ((($num_sign = $num[0]) ===
'+') || ($num_sign ===
'-')) {
108 $num = substr($num, 1);
112 if ($num_sign ===
'+') {
117 if ((($exp_sign = $exp[0]) ===
'+') || ($exp_sign ===
'-')) {
118 $exp = substr($exp, 1);
120 trigger_error(
"Could not convert exponential notation to decimal notation: invalid float string '$float_str'", E_USER_ERROR);
124 $right_dec_places = (($dec_pos = strpos($num,
'.')) ===
false) ? 0 : strlen(substr($num, $dec_pos+1));
126 $left_dec_places = ($dec_pos ===
false) ? strlen($num) : strlen(substr($num, 0, $dec_pos));
129 if ($exp_sign ===
'+') {
130 $num_zeros = $exp - $right_dec_places;
132 $num_zeros = $exp - $left_dec_places;
136 $zeros = str_pad(
'', $num_zeros,
'0');
139 if ($dec_pos !==
false) {
140 $num = str_replace(
'.',
'', $num);
144 if ($exp_sign ===
'+') {
145 return $num_sign . $num . $zeros;
149 return $num_sign .
'0.' . $zeros . $num;
comp($left_operand, $right_operand, $scale=null)
Compares two numbers.
equals($left_operand, $right_operand, $scale=null)
{Checks whether or not two numbers are identical.bool}
applyScale($number, $scale=null)
This method adapts the behaviour of bcscale()
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings.
pow($left_operand, $right_operand, $scale=null)
Raises a number to another.
exp2dec($float_str)
Moved from ilMath...
round($value, $precision=0)
string