How to convert string into numbers

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
infomamun
Forum Contributor
Posts: 102
Joined: Mon Dec 28, 2009 7:48 pm

How to convert string into numbers

Post by infomamun »

Hi there
I want to convert a string into number which I got from scrapping. But problem is if the string contains decimal point it is automatically converted as round number.


$str = <? echo "10.42" ?>;
<? echo (int)$str; ?>

but the output is 10.

How to convert is as 10.42 instead 10 by a single line of code?
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: How to convert string into numbers

Post by Darhazer »

use (float) instead of (int)
infomamun
Forum Contributor
Posts: 102
Joined: Mon Dec 28, 2009 7:48 pm

Re: How to convert string into numbers

Post by infomamun »

Thanks a lot.
Post Reply