Reply to Re: from string to integer/double problem

Your name:

Reply:


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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° 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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация