Say I have 1.234 I want to get the .234
I tried echo 1.234%1 //I get 0
(The tags says PHP as this might be an issue only with PHP, but I really am looking for the general solution).
php's %
modulo operator converts its arguments to integers. To get a floating-point modulus, use fmod
:
echo fmod(1.234, 1);
You can remove the whole number from the number itself. in php its:
$num = 1.234;
echo $num - floor($num);
Subtract the integer portion of $x ((int)$x
) from $x:
$x = 1.234;
$d = $x - (int)$x;
// $d now equals 0.234
echo $d;
Example
Just substract integer part 1.234 - (int)1.234
Try this:
echo 1.234 - intval(1.234);
精彩评论