EngineeringValidations.php 713 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Exception;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
  5. class EngineeringValidations
  6. {
  7. /**
  8. * @param mixed $value
  9. */
  10. public static function validateFloat($value): float
  11. {
  12. if (!is_numeric($value)) {
  13. throw new Exception(ExcelError::VALUE());
  14. }
  15. return (float) $value;
  16. }
  17. /**
  18. * @param mixed $value
  19. */
  20. public static function validateInt($value): int
  21. {
  22. if (!is_numeric($value)) {
  23. throw new Exception(ExcelError::VALUE());
  24. }
  25. return (int) floor((float) $value);
  26. }
  27. }