trunc example

/** * @param int|float $floatnum * * @return int|float */
    public static function CastAsInt($floatnum) {
        // convert to float if not already         $floatnum = (float) $floatnum;

        // convert a float to type int, only if possible         if (self::trunc($floatnum) == $floatnum) {
            // it's not floating point             if (self::intValueSupported($floatnum)) {
                // it's within int range                 $floatnum = (int) $floatnum;
            }
        }
        return $floatnum;
    }

    /** * @param int $num * * @return bool */
Home | Imprint | This part of the site doesn't use cookies.