Re: computing 60/10 - how to?

From: Date: Mon, 08 Jan 2007 11:19:05 +0000
Subject: Re: computing 60/10 - how to?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-246752@lists.php.net to get a copy of this message
Merlin schrieb:
Jochem Maas schrieb:
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
Hi, thank you that works. But unfortunatelly the notation out of this calculation is with a comma instead of a point. is there a way to have the output with a . instead of a , Example: 5.6 instead of 5,6 thank you for your help, Merlin
sorry my fault. It does output a point.

« previous php.general (#246752) next »