$n = 1.25;
$whole = floor($n); // 1
$fraction = $n - $whole; // .25
然后与1/4,1/2,3/4等比较。
在负数的情况下,使用:
function NumberBreakdown($number, $returnUnsigned = false)
{
$negative = 1;
if ($number < 0)
{
$negative = -1;
$number *= -1;
}
if ($returnUnsigned){
return array(
floor($number),
($number - floor($number))
);
}
return array(
floor($number) * $negative,
($number - floor($number)) * $negative
);
}
$ returnUnsigned停止从-1.25到-1& -0.25