self::MAX || fmod($value * 4, 1.0) !== 0.0) { throw new InvalidEstimatedHours; } $this->value = $value; } public static function fromString(string $value): self { $value = str_replace(',', '.', trim($value)); if (! is_numeric($value)) { throw new InvalidEstimatedHours; } return new self((float) $value); } /** * E.g. "12.5", without trailing zeros. */ public function format(): string { return rtrim(rtrim(number_format($this->value, 2, '.', ''), '0'), '.'); } }