473,804 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 41241
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***@bhg byrzcv.arg)
Feb 15 '07 #2
Rik
On Thu, 15 Feb 2007 18:32:15 +0100, <pi*******@gmai l.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
4395
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 exactly: numeric(10, 5) and numeric. Given that the structure to fill-up is DBNUMERIC defined as:
5
5516
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 problem I ran into is a float with value INT_MAX assigned to an int results in the value -2147483648 being assigned, but if the conversion takes place in an expression INT_MAX is assigned as I would expect: int...
2
1453
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
2484
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 display them as strings: echo $value; // Returns 0.4 echo "'$value'"; // Returns '0.4' But I can not convert them into float: echo floatval($value); // Returns 0
5
2479
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
7874
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 (readXml.Value) ; Any suggestions for an alternate function ..
6
17856
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) (1000000000 * giga_hertz);
7
4476
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 not a number. Try again. and ask the user to type in another number. Here's what I have so far. Code:
2
15381
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 someone know how can I convert a string into a float or at least convert type string to char * then use atof().
0
9715
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10097
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9175
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.