Blame view

vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php 1003 Bytes
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  <?php
  
  namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
  
  use PhpOffice\PhpSpreadsheet\Calculation\Exception;
  
  class Trunc
  {
      /**
       * TRUNC.
       *
       * Truncates value to the number of fractional digits by number_digits.
       *
       * @param float $value
       * @param int $digits
       *
       * @return float|string Truncated value, or a string containing an error
       */
      public static function evaluate($value = 0, $digits = 0)
      {
          try {
              $value = Helpers::validateNumericNullBool($value);
              $digits = Helpers::validateNumericNullSubstitution($digits, null);
          } catch (Exception $e) {
              return $e->getMessage();
          }
  
          $digits = floor($digits);
  
          // Truncate
          $adjust = 10 ** $digits;
  
          if (($digits > 0) && (rtrim((string) (int) ((abs($value) - abs((int) $value)) * $adjust), '0') < $adjust / 10)) {
              return $value;
          }
  
          return ((int) ($value * $adjust)) / $adjust;
      }
  }