You are here: Re: from string to integer/double problem « All PHP « IT news, forums, messages
Re: from string to integer/double problem

Posted by Oli Filth on 11/15/05 21:45

nescio said the following on 15/11/2005 19:22:
> hello,
>
> i have got a variable with the value '$rij[2] = "16.60" (it is the price of
> something);
> but i want this value to be a integer or a double, because i need to know
> how many cents the amount is.
>
> i have tried 'settype($variable, "double"); but it is not working;
>
> ---------------source code ---------------------------
> function bedragInCenten($bedrag){
> $nieuw = settype($bedrag, "double");

If you read the manual for settype(), you will see that the return value
is a Boolean, TRUE for success, FALSE for failure. $bedrag itself will
have its type changed.

Note also (although this won't affect the operation) that "double" is
deprecated as of PHP 4.2.0. Use "float" instead.

Alternatively, use $nieuw = floatval($bedrag);

> $nieuw = $nieuw * 100;
> return $nieuw;
> }
>
> $demo = "16.60";

Why put it in string, why not just $demo = 16.60 ??

>
> bedragInCenten($demo);
>
> --------------------------------------------------------
>
> i always get '100' as an outcome.
> can someone explain this to me, and show me how to do it wright?
>

--
Oli

 

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

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