ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Dollar.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
8 class Dollar
9 {
21  public static function format($number, $precision = 2): string
22  {
23  return Format::DOLLAR($number, $precision);
24  }
25 
41  public static function decimal($fractionalDollar = null, $fraction = 0)
42  {
43  $fractionalDollar = Functions::flattenSingleValue($fractionalDollar);
44  $fraction = (int) Functions::flattenSingleValue($fraction);
45 
46  // Validate parameters
47  if ($fractionalDollar === null || $fraction < 0) {
48  return Functions::NAN();
49  }
50  if ($fraction == 0) {
51  return Functions::DIV0();
52  }
53 
54  $dollars = floor($fractionalDollar);
55  $cents = fmod($fractionalDollar, 1);
56  $cents /= $fraction;
57  $cents *= 10 ** ceil(log10($fraction));
58 
59  return $dollars + $cents;
60  }
61 
77  public static function fractional($decimalDollar = null, $fraction = 0)
78  {
79  $decimalDollar = Functions::flattenSingleValue($decimalDollar);
80  $fraction = (int) Functions::flattenSingleValue($fraction);
81 
82  // Validate parameters
83  if ($decimalDollar === null || $fraction < 0) {
84  return Functions::NAN();
85  }
86  if ($fraction == 0) {
87  return Functions::DIV0();
88  }
89 
90  $dollars = floor($decimalDollar);
91  $cents = fmod($decimalDollar, 1);
92  $cents *= $fraction;
93  $cents *= 10 ** (-ceil(log10($fraction)));
94 
95  return $dollars + $cents;
96  }
97 }
static fractional($decimalDollar=null, $fraction=0)
DOLLARFR.
Definition: Dollar.php:77
static format($number, $precision=2)
DOLLAR.
Definition: Dollar.php:21
static decimal($fractionalDollar=null, $fraction=0)
DOLLARDE.
Definition: Dollar.php:41
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649