ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTFloatDefinition.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected int $decimals;
24 protected ?float $min_value;
25 protected ?float $max_value;
26 protected string $suffix = '';
27
28 // properties
29
30 public function handleNumber($a_value): ?float
31 {
32 if (!is_numeric($a_value)) {
33 $a_value = null;
34 }
35 if ($a_value !== null) {
36 // round?
37 $a_value = (float) $a_value;
38 }
39 return $a_value;
40 }
41
42 public function getMin(): ?float
43 {
44 return $this->min_value;
45 }
46
47 public function setMin(?float $a_value): void
48 {
49 $this->min_value = $this->handleNumber($a_value);
50 }
51
52 public function getMax(): ?float
53 {
54 return $this->max_value;
55 }
56
57 public function setMax(?float $a_value): void
58 {
59 $this->max_value = $this->handleNumber($a_value);
60 }
61
62 public function getSuffix(): string
63 {
64 return $this->suffix;
65 }
66
67 public function setSuffix(?string $a_value): void
68 {
69 $this->suffix = $a_value === null ? '' : trim($a_value);
70 }
71
72 public function isComparableTo(ilADT $a_adt): bool
73 {
74 // has to be number-based
75 return ($a_adt instanceof ilADTFloat);
76 }
77
78 public function reset(): void
79 {
80 parent::reset();
81 $this->setDecimals(1);
82 }
83
84 public function getDecimals(): int
85 {
86 return $this->decimals;
87 }
88
89 public function setDecimals(int $a_value): void
90 {
91 // max precision ?!
92 $this->decimals = max(1, abs($a_value));
93 }
94}
ADT definition base class.
reset()
Init property defaults.
isComparableTo(ilADT $a_adt)
Check if given ADT is comparable to self.
ADT base class.
Definition: class.ilADT.php:26