You are here: Re: [PHP] Converting integer type to long « PHP « IT news, forums, messages
Re: [PHP] Converting integer type to long

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация