Say I have 1.234 I want to get the .234
I tried echo 1.234%1 //I get 0
I am rusty, what is the correct way?
(The tags says PHP as this might be an issue only with PHP, but I really am looking for the general solution).
Say I have 1.234 I want to get the .234
I tried echo 1.234%1 //I get 0
I am rusty, what is the correct way?
(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);
Just substract integer part 1.234 - (int)1.234