|
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
[Back to original message]
|