Re: Converting integer type to long

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux