Ingeger problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Ingeger problem

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Ingeger problem

Post by pickle »

On line 2 - output the value of $dollarTotal to make sure it's what you think it is.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Re: Ingeger problem

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Ingeger problem

Post by pickle »

try strlen() for the testing.

Maybe this'll help: http://ca3.php.net/manual/en/language.t ... er.casting
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Re: Ingeger problem

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Ingeger problem

Post by pickle »

That means that your $dollarTotal as a string has 35 characters. That might be your problem.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Re: Ingeger problem

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Ingeger problem

Post by pickle »

The extra characters are probably spaces. What I usually do is:

Code: Select all

echo "<pre>|$myVariable|</pre>";
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Re: Ingeger problem

Post 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!
:wink:
Post Reply