By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

converting string to float

P: n/a
I'm trying to convert string to float and my float after conversion is
0 (zero). Here is my code:

$c = $currencies->format($cart->show_total());
echo gettype($c);
echo (float)$c;

$c = 39.59
gettype($c) = string
echo (float)$c; = 0

any other string such as "2.34" converted into float exactly the same
way works fine.

Thanks,
JP

Feb 15 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
pi*******@gmail.com kirjoitti:
I'm trying to convert string to float and my float after conversion is
0 (zero). Here is my code:

$c = $currencies->format($cart->show_total());
echo gettype($c);
echo (float)$c;

$c = 39.59
gettype($c) = string
echo (float)$c; = 0

any other string such as "2.34" converted into float exactly the same
way works fine.

Thanks,
JP
What does $currencies->format() do and why wouldn't you just use the
$cart->show_total()?
--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Feb 15 '07 #2

P: n/a
Rik
On Thu, 15 Feb 2007 18:32:15 +0100, <pi*******@gmail.comwrote:
I'm trying to convert string to float and my float after conversion is
0 (zero). Here is my code:

$c = $currencies->format($cart->show_total());
echo gettype($c);
echo (float)$c;

$c = 39.59
gettype($c) = string
echo (float)$c; = 0

any other string such as "2.34" converted into float exactly the same
way works fine.
Are you looking at this in a HTML page? If so, what does the source say?
Someone just recently had this problem because the value was
'<b>12.34</b>' rather then '12.34'.... Try an echo htmlentities($c);
--
Rik Wasmus
Feb 15 '07 #3

P: n/a
Are you looking at this in a HTML page? If so, what does the source say?
Someone just recently had this problem because the value was
'<b>12.34</b>' rather then '12.34'.... Try an echo htmlentities($c);
Thanks both of you. The htmlentities($c) output was $12.34 caused by
the $currencies->format() function.

Feb 15 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.