首页 > 技术文档 > 技术文档 > 详解PHP中2个float的比较

详解PHP中2个float的比较

时间:2016-2-29 已查看1991次

//等于比较


function floatcmp($f1,$f2,$precision = 10) {// are 2 floats equal

    $e = pow(10,$precision);

    $i1 = intval($f1 * $e);

    $i2 = intval($f2 * $e);

    return ($i1 == $i2);

}


//大于比较

function floatgtr($big,$small,$precision = 10) {// is one float bigger than another

    $e = pow(10,$precision);

    $ibig = intval($big * $e);

    $ismall = intval($small * $e);

    return ($ibig > $ismall);

}


//大于等于比较

function floatgtre($big,$small,$precision = 10) {// is on float bigger or equal to another

    $e = pow(10,$precision);

    $ibig = intval($big * $e);

    $ismall = intval($small * $e);

    return ($ibig >= $ismall);

}


上一篇:百度地图api描绘车辆历史轨迹图 下一篇:详解PHP执行定时任务的实现思路