ILIAS  release_8 Revision v8.23
class.ilADTFloatDefinition.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 {
7  protected int $decimals;
8  protected ?float $min_value;
9  protected ?float $max_value;
10  protected string $suffix = '';
11 
12  // properties
13 
14  public function handleNumber($a_value): ?float
15  {
16  if (!is_numeric($a_value)) {
17  $a_value = null;
18  }
19  if ($a_value !== null) {
20  // round?
21  $a_value = (float) $a_value;
22  }
23  return $a_value;
24  }
25 
26  public function getMin(): ?float
27  {
28  return $this->min_value;
29  }
30 
31  public function setMin(?float $a_value): void
32  {
33  $this->min_value = $this->handleNumber($a_value);
34  }
35 
36  public function getMax(): ?float
37  {
38  return $this->max_value;
39  }
40 
41  public function setMax(?float $a_value): void
42  {
43  $this->max_value = $this->handleNumber($a_value);
44  }
45 
46  public function getSuffix(): string
47  {
48  return $this->suffix;
49  }
50 
51  public function setSuffix(?string $a_value): void
52  {
53  $this->suffix = $a_value === null ? '' : trim($a_value);
54  }
55 
56  public function isComparableTo(ilADT $a_adt): bool
57  {
58  // has to be number-based
59  return ($a_adt instanceof ilADTFloat);
60  }
61 
62  public function reset(): void
63  {
64  parent::reset();
65  $this->setDecimals(1);
66  }
67 
68  public function getDecimals(): int
69  {
70  return $this->decimals;
71  }
72 
73  public function setDecimals(int $a_value): void
74  {
75  // max precision ?!
76  $this->decimals = max(1, abs($a_value));
77  }
78 }
ADT base class.
Definition: class.ilADT.php:11
ADT definition base class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...