1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- /**
- * The Feeler framework, licensed under Mit license
- * Author: Rick Guo
- */
- class Number{
- public static function truncateDecimal($number, $decimalDigits = -1){
- if(is_numeric($number) && is_int($decimalDigits)){
- $number = (float)$number;
-
- if($decimalDigits > 0){
- $tempDecimalDigits = $decimalDigits + 1;
- $number = substr(sprintf("%.{$tempDecimalDigits}f", $number), 0, -1);
- }
- else if($decimalDigits == 0){
- $number = (int)$number;
- }
- }
-
- return $number;
- }
-
- public static function isInt($number){
- return is_numeric($number) && !is_float($number) ? true : false;
- }
-
- public static function isFloat($number){
- return is_numeric($number) && !is_int($number) ? true : false;
- }
-
- public static function isNumeric($number){
- return is_numeric($number);
- }
- }
|