Re: computing 60/10 - how to?

From: Date: Mon, 08 Jan 2007 10:28:13 +0000
Subject: Re: computing 60/10 - how to?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-246748@lists.php.net to get a copy of this message
Merlin wrote: > Hi there, > > I do have a text value inside a variable: exif[FNumber] = 56/10 which I > would like to save as a float value: 5,6 into a database. > > How can I compute this 56/10? I tried things like calculate() or math() > but did not find the propper function to do this. > > Can anybody help, please? if you know the string is always in the form: "number / number" you might do something like: <?php $str = "56/10"; $bits = explode("/", $str); $num1 = floatval($bits[0]) / floatval($bits[1]); echo $num1; ?> another way to go *might* be to use eval() - note that eval() is almost *always* the wrong solution to a problem: <?php $str = "56/10"; eval("\$num1 = {$str};"); echo $num1; ?> > > Thank you in advance, > > Merlin >

« previous php.general (#246748) next »