Simple problems require simple solutions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
709 B

  1. <?php
  2. namespace App\DTO;
  3. use Spatie\LaravelData\Data;
  4. class DurationResult extends Data
  5. {
  6. /**
  7. * @param int $days
  8. * @param int $weekDays
  9. * @param int $weeks
  10. * @return void
  11. */
  12. public function __construct(
  13. public int|float $days,
  14. public int|float $weekDays,
  15. public int|float $weeks,
  16. ) {
  17. $this->days = $this->formatFloat($days);
  18. $this->weekDays = $this->formatFloat($weekDays);
  19. $this->weeks = $this->formatFloat($weeks);
  20. }
  21. private function formatFloat(int|float $val): int|float
  22. {
  23. if (!is_float($val)) {
  24. return $val;
  25. }
  26. return (float) number_format($val, 5, '.', '');
  27. }
  28. }