Number.php 807 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * The Feeler framework, licensed under Mit license
  4. * Author: Rick Guo
  5. */
  6. class Number{
  7. public static function truncateDecimal($number, $decimalDigits = -1){
  8. if(is_numeric($number) && is_int($decimalDigits)){
  9. $number = (float)$number;
  10. if($decimalDigits > 0){
  11. $tempDecimalDigits = $decimalDigits + 1;
  12. $number = substr(sprintf("%.{$tempDecimalDigits}f", $number), 0, -1);
  13. }
  14. else if($decimalDigits == 0){
  15. $number = (int)$number;
  16. }
  17. }
  18. return $number;
  19. }
  20. public static function isInt($number){
  21. return is_numeric($number) && !is_float($number) ? true : false;
  22. }
  23. public static function isFloat($number){
  24. return is_numeric($number) && !is_int($number) ? true : false;
  25. }
  26. public static function isNumeric($number){
  27. return is_numeric($number);
  28. }
  29. }