Page 1 of 1
Ingeger problem
Posted: Mon May 26, 2008 4:34 am
by Addos
I wonder if anyone can see what might be happening here. I have a string that returns a value 40.00 . This I know (from my cart) is outputted as a ‘string’ value and not an integer. When I convert it to and integer value is returns a ‘0’ value and I cannot see why.
This is how I’m trying to do this.
Code: Select all
<?PHP $dollarTotal =(getPriceList); ?>
<?PHP settype($dollarTotal, "int") ; ?> // changes it to an int
<?PHP echo gettype($dollarTotal); ?> // proves its an int
<?PHP echo $dollarTotal ; ?> returns a blank value
So what it missing from the maths? I have tried using trim just in case there is white space but this also is not the problem.
Thanks for any help
Re: Ingeger problem
Posted: Mon May 26, 2008 10:16 am
by pickle
On line 2 - output the value of $dollarTotal to make sure it's what you think it is.
Re: Ingeger problem
Posted: Mon May 26, 2008 10:26 am
by Addos
On line 2 - output the value of $dollarTotal to make sure it's what you think it is.
<?PHP echo $dollarTotal ; ?> // gives 40.00
Yeah thanks I have and it returns 40.00 which is what I'm expecting. I wish I could test the string to see if there are hidden elements (such as HTML maybe) that are not visable. I have tried var_dump and nothing is giving me a clue.
Very strange
Re: Ingeger problem
Posted: Mon May 26, 2008 10:40 am
by pickle
Re: Ingeger problem
Posted: Mon May 26, 2008 11:04 am
by Addos
Interesting. When I run strlen($dollarTotal) it outputs 35 . I'm not sure what that refers to but the variable '$dollarTotal' has the value of 40.00.
I was looking and working on 'casting' earlier too but didn't manage to get anywhere.
Thanks again
Re: Ingeger problem
Posted: Mon May 26, 2008 11:06 am
by pickle
That means that your $dollarTotal as a string has 35 characters. That might be your problem.
Re: Ingeger problem
Posted: Mon May 26, 2008 11:09 am
by Addos
Yep was thinking that. Is there anything in the manual that will output it completely i.e html and all so I can see exactly what's there?
Thanks again
Re: Ingeger problem
Posted: Mon May 26, 2008 11:24 am
by pickle
The extra characters are probably spaces. What I usually do is:
Which lets me see pretty much everything. If you think there is hidden html code, just view the source of your page & see what's there.
Re: Ingeger problem
Posted: Mon May 26, 2008 11:25 am
by Addos
Okay I found the culprit.
<span id="divPrice3"> 40.00 </span> is what’s in the source view so I needed to simply use strip tags and this sorted it out. Ahh 24hours lost but I guess a lot learned!
Thanks to all for the help!
