473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

converting string to float

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
3 41214
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Giovanni Azua | last post by:
Hello all, I need to return back to TSQL two numeric values from an Extended Stored Procedure developed in C. As result my C dll program produces two float values, the TSQL side expects to have...
5
by: Code4u | last post by:
In the course of writing numerical code I needed to convert a float to an int with a defined behavior: if the float is great than INT_MAX, set the int to INT_MAX, otherwise assign directly. The...
2
by: pango | last post by:
I write below code in my program: float f=0.371f; int i=(int)(f*1000.0f); I think the result of "i" should be "371",but in fact it is "370",why?How to solve it?
3
by: acsandras | last post by:
I am trying to extract data from an iso-8859-1 encoded XML document. I open the file, and read each line after each other, and extract some values. These values are behaving oddly, though. I can...
5
by: eric.goforth | last post by:
Hello, float.parse(MyString) seems to work to convert a string to a float, but how do I change it back? e.g. (string) (Myfloat1 - Myfloat2)
5
by: vivekaseeja | last post by:
Hi , Trying to convert a string value to a float value after reading the value from an XML file , but not sure what function to use. The following only works for integers Int32.Parse...
6
by: subaruwrx88011 | last post by:
Is there anyway to convert a float to an unsigned int without loss of precision? Here is what I have.... float giga_hertz; unisigned int hertz; giga_hertz = 4.2; hertz = (unsigned int)...
7
by: DirtyRasa | last post by:
Here is what my professor told me to to. Write a function that converts a string to a float and returns a float. Test your function by entering f4 and with 4f. Both should say Data entered was...
2
thatos
by: thatos | last post by:
I have this line of code in my program string line = "1"; I would like to convert line into a float, now I can't use float i = atof(line) because atof() takes in char * as its argument. Does...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.