28     public function applyScale($left_operand, 
int $scale = null): string
    30         if (is_numeric($left_operand)) {
    31             $scale = (
int) $scale;
    33             $left_operand = $this->
exp2dec($left_operand);
    34             if (strpos($left_operand, 
'.') === 
false) {
    35                 $number_of_decimals = 0;
    37                 $number_of_decimals = strlen(substr($left_operand, strpos($left_operand, 
'.') + 1));
    40             if ($number_of_decimals > 0 && $number_of_decimals < $scale) {
    41                 $left_operand = str_pad($left_operand, $scale - $number_of_decimals, 
'0');
    42             } elseif ($number_of_decimals > $scale) {
    43                 $left_operand = substr($left_operand, 0, -($number_of_decimals - $scale));
    53     public function round($value, 
int $precision = 0): string
    55         return number_format($value, $precision, 
'.', 
'');
    61     public function equals($left_operand, $right_operand, 
int $scale = null): bool
    63         return $this->
comp($left_operand, $right_operand, $scale) === 0;
    74         if (null === $number) {
    78         $number = trim((
string) $number);
    79         $number = $this->
exp2dec($number);
    80         $locale_info = localeconv();
    82         if ($locale_info[
'decimal_point'] !== 
'.') {
    84             $number_of_decimals = (
int) ini_get(
'precision') - (
int) floor(log10(abs($number)));
    85             if (0 > $number_of_decimals) {
    86                 $number *= 10 ** $number_of_decimals;
    87                 $append = str_repeat(
'0', -$number_of_decimals);
    88                 $number_of_decimals = 0;
    91             return number_format($number, $number_of_decimals, 
'.', 
'') . $append;
   101     protected function exp2dec($float_str): string
   105         $original = $float_str; 
   106         $float_str = (string) ((
float) ($float_str));
   107         $float_str = str_replace(
",", 
".", $float_str); 
   110         if (($pos = stripos($float_str, 
'e')) !== 
false) {
   112             $exp = substr($float_str, $pos + 1);
   113             $num = substr($float_str, 0, $pos);
   116             if ((($num_sign = $num[0]) === 
'+') || ($num_sign === 
'-')) {
   117                 $num = substr($num, 1);
   121             if ($num_sign === 
'+') {
   126             if ((($exp_sign = $exp[0]) === 
'+') || ($exp_sign === 
'-')) {
   127                 $exp = substr($exp, 1);
   129                 trigger_error(
"Could not convert exponential notation to decimal notation: invalid float string '$float_str'", E_USER_ERROR);
   133             $right_dec_places = (($dec_pos = strpos($num, 
'.')) === 
false) ? 0 : strlen(substr($num, $dec_pos + 1));
   135             $left_dec_places = ($dec_pos === 
false) ? strlen($num) : strlen(substr($num, 0, $dec_pos));
   138             if ($exp_sign === 
'+') {
   139                 $num_zeros = $exp - $right_dec_places;
   141                 $num_zeros = $exp - $left_dec_places;
   145             $zeros = str_pad(
'', $num_zeros, 
'0');
   148             if ($dec_pos !== 
false) {
   149                 $num = str_replace(
'.', 
'', $num);
   153             if ($exp_sign === 
'+') {
   154                 return $num_sign . $num . $zeros;
   158             return $num_sign . 
'0.' . $zeros . $num;
 This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
round($value, int $precision=0)
 
comp($left_operand, $right_operand, int $scale=null)
Compares two numbers. 
 
normalize($number)
This function fixes problems which occur when locale ist set to de_DE for example, because bc* function expecting strings. 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
applyScale($left_operand, int $scale=null)
 
equals($left_operand, $right_operand, int $scale=null)