Re: computing 60/10 - how to?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux