|
Posted by Torgny Bjers on 08/03/05 08:36
Wee Keat wrote:
>The problem is, I have not been able to convert PHP's integer/float type
>to long because there is no function that does it. Or is there?
>
The reason why is because there's no real long support in PHP.
But, since you mention a value such as 0.01, you are not looking for a
long, you are looking for a float. So, what you need to do is to
type-cast all the values involved in the making of the variable that
holds the float value.
For instance:
$var = (float)$var1 / (float)$var2;
$query = sprintf('%.2f %s', (float)$var, $string);
I haven't found the exact points where PHP forgets it's a float, but
it's always good to make sure all mathematical operations are performed
on the value as a float by type-casting, otherwise it might lose
information.
Regards,
Torgny
Navigation:
[Reply to this message]
|