|
Posted by Kim Andrι Akerψ on 11/15/05 21:48
nescio wrote:
> 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");
> $nieuw = $nieuw * 100;
> return $nieuw;
> }
>
> $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?
The settype() function only returns TRUE or FALSE based on whether or
not it the variable type was successfully changed. The variable
specified within the settype() function will be changed.
http://php.net/settype
This will most likely produce the intended result:
<?php
function bedragInCenten($bedrag){
settype($bedrag, "double");
$bedrag *= 100;
return $bedrag;
}
$demo = "16.60";
bedragInCenten($demo);
?>
--
Kim AndrΓ© AkerΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
[Back to original message]
|