By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

Problem with multiplying doubles

P: n/a
Hello,

I wanted to create a currency translator with PHP.

The code looks like this:
<?php

$faktor=2.95583; // a double
$dm = $euro * $faktor; // $euro is a double variable with the
original value
// $dm is a double variable

echo $dm; // prints 10 when $euro is 5

?>

all varables are double, I checked this with the gettype() function
The calculation seems to take only the integers and cuttig off the .9
before calculating

Another example:
echo 5.5*2.2; // prints 10, should be about 11

what can I do if I want to multily doubles to get the correct answer?

I hope anyone can help me!
thanks in advance for your help!

christine
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
ch*******@hutt-edv.de (christine) wrote:
$faktor=2.95583; // a double
$dm = $euro * $faktor; // $euro is a double variable with the
original value
// $dm is a double variable

echo $dm; // prints 10 when $euro is 5
No, it prints 14.77915 when $euro is 5
Another example:
echo 5.5*2.2; // prints 10, should be about 11


No, it prints 12.1, and that's exactly what it should do.

JOn
Jul 17 '05 #2

P: n/a
No it worked for me ...

Savut

"christine" <ch*******@hutt-edv.de> wrote in message
news:f1**************************@posting.google.c om...
Hello,

I wanted to create a currency translator with PHP.

The code looks like this:
<?php

$faktor=2.95583; // a double
$dm = $euro * $faktor; // $euro is a double variable with the
original value
// $dm is a double variable

echo $dm; // prints 10 when $euro is 5

?>

all varables are double, I checked this with the gettype() function
The calculation seems to take only the integers and cuttig off the .9
before calculating

Another example:
echo 5.5*2.2; // prints 10, should be about 11

what can I do if I want to multily doubles to get the correct answer?

I hope anyone can help me!
thanks in advance for your help!

christine

Jul 17 '05 #3

P: n/a
Jon Kraft wrote:
ch*******@hutt-edv.de (christine) wrote:
$faktor=2.95583; // a double
$dm = $euro * $faktor; // $euro is a double variable with the
original value
// $dm is a double variable

echo $dm; // prints 10 when $euro is 5


No, it prints 14.77915 when $euro is 5
Another example:
echo 5.5*2.2; // prints 10, should be about 11


No, it prints 12.1, and that's exactly what it should do.

JOn


$ cat xx.php
<?php
ini_set('precision', '2');

$euro = 5;
$faktor = 2.95583;
$dm = $euro * $faktor;

echo "--------\n$dm\n";

echo 5.5*2.2, "\n";
?>

$ php xx.php
--------
15
12

Check your php.ini !
--
--= my mail address only accepts =--
--= Content-Type: text/plain =--
--= Size below 10K =--
Jul 17 '05 #4

P: n/a
ch*******@hutt-edv.de (christine) wrote in message news:<f1**************************@posting.google. com>...
Hello,

I wanted to create a currency translator with PHP.

The code looks like this:
<?php

$faktor=2.95583; // a double
$dm = $euro * $faktor; // $euro is a double variable with the
original value
// $dm is a double variable

echo $dm; // prints 10 when $euro is 5

?>

all varables are double, I checked this with the gettype() function
The calculation seems to take only the integers and cuttig off the .9
before calculating

Another example:
echo 5.5*2.2; // prints 10, should be about 11


I installed PHP 4.3.4 instead of PHP 4.0.0 and now it works.

Thanks for your answers!

christine
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.