simple multiplication 8200*1000
Posted by: christophe charron (---.w86-216.abo.wanadoo.fr)
Date: September 25, 2007 08:53AM

Hi,

I 've got a very "funny" thing with last WAMP5
When trying to multiply 8100 by or 8200 by 1000 the result is displayed in scientific notation. Why not if it was for all values ... But when I try the same operations with 8099 or 8201, I obtain a "correct" display.
And on my redhat internet server with php 5.1.6, the same script gives good results
localeinfo are the same for the 2 servers.
Here is the internet server localeinfo
[test03.christophe-charron.org]
Here is the local screenshot
[test03.christophe-charron.org]
and there the internet script
en distant : [test03.christophe-charron.org]

The script is abolutly the same

<?php
header('Content-type: text/plain; charset=utf-8');
define('EOL', "\r\n"winking smiley;
multiplie("8099.000"winking smiley;
multiplie("8100.000"winking smiley;
multiplie("8200.000"winking smiley;
multiplie("8201.000"winking smiley;
multiplie("9300.000"winking smiley;
function multiplie($toto) {
echo ("------------------------"winking smiley.EOL;
$qte_stock= $toto;
echo $qte_stock.EOL;
$val_qte_stock=$qte_stock*10;
echo $val_qte_stock.EOL;
$val_qte_stock=$qte_stock*100;
echo $val_qte_stock.EOL;
$val_qte_stock=$qte_stock*1000;
echo $val_qte_stock.EOL;
echo ("double -> ". (double) $val_qte_stock).EOL;
$val_qte_stock=$qte_stock*10000;
echo $val_qte_stock.EOL;
echo ("double -> ". (double) $val_qte_stock).EOL;
echo EOL;
}
?>

I started a topic in french forum too. An other guy has the same problem, with my script.

But still no solution and as i'd like to use the result of my arithmetic operations to sort datas it doesn't really work !!
Se here the "sorted" result [test03.christophe-charron.org]

Any idea? Is it a bug in last WAMP5 ?
Could anybody test my script on is own wamp5 server, whatever its version, to tell me if we obtain same results ?

And sorry for my english, I'm french !!
--
Cordially,
Christophe Charron

Options: ReplyQuote
Re: simple multiplication 8200*1000
Posted by: clorne (---.dynamic.dsl.as9105.com)
Date: September 25, 2007 07:29PM

On WindowsXP with PHP5.2.4 your code produces scientific notations as you say. It is very curious and I don't know why but is there any reason you can't use printf instead of echo it would be a very much more flexible - for example something like this

<?php
header('Content-type: text/plain; charset=utf-8');
define('EOL', "\r\n"winking smiley;
multiplie("8099.000"winking smiley;
multiplie("8100.000"winking smiley;
multiplie("8200.000"winking smiley;
multiplie("8201.000"winking smiley;
multiplie("9300.000"winking smiley;
function multiplie($toto) {
echo ("------------------------"winking smiley.EOL;
$qte_stock= $toto;
echo $qte_stock . EOL;
$val_qte_stock=$qte_stock*10;
printf("%01.3f".EOL, $val_qte_stock);
$val_qte_stock=$qte_stock*100;
printf("%01.3f".EOL, $val_qte_stock);
$val_qte_stock=$qte_stock*1000;
printf("%01.3f".EOL, $val_qte_stock);
printf("double -> "."%u".EOL, $val_qte_stock);
$val_qte_stock=$qte_stock*10000;
printf("%01.3f".EOL, $val_qte_stock);
printf("double -> "."%u".EOL, $val_qte_stock);
echo EOL;
}
?>

but maybe you can't for some reason

Options: ReplyQuote
Re: simple multiplication 8200*1000
Posted by: christophe charron (---.w86-216.abo.wanadoo.fr)
Date: September 26, 2007 01:38PM

Thanks for your suggestion. It works ... but i'd still like to know what kind of bug it is. Is it worth do downgrade to a previous release of WAMP , and then, which one. ?
Do you think it's a php bug or a wamp bug ?
And as long as I don't understand, any echo with numeric values seems to be unsafe ...

--
Cordially,
Christophe Charron



--
Cordialement,
Christophe Charron

Options: ReplyQuote
Re: simple multiplication 8200*1000
Posted by: clorne (---.dynamic.dsl.as9105.com)
Date: September 26, 2007 05:34PM

I don't think it's a bug more of a PHP anomaly and nothing to do with WAMP but check with PHP manual for correct usage and differences between echo, printf and sprintf.

Options: ReplyQuote


Sorry, only registered users may post in this forum.