title: PHP - How to validate float number has maximum 2 digits
body: <p>I have to validate if a float number has maximum two digits.</p>
  
  <p>I've tried a lot of methods but all fails in more or lase cases.</p>
  
  <p>Last of them were:</p>
  
  <pre><code>//fails for 2638655.99
  private function hasMoreThanTwoDecimals(string $number): bool
  {
      $number = abs($number);
      $intPart = floor($number);
      $floatPart = $number - $intPart;
  
      return (strlen($floatPart) &gt; 4);
  }
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>//fails for 36.62
  private function hasMoreThanTwoDecimals(string $number): bool
  {
      return $number * 100 - floor($number * 100) &gt; 0.00001;
  }
  </code></pre>
  
  <p>What other methods do you use?</p>