Hi,

I got a function that do a very strange calculation ... Here is the code
fragment


function ChiffreEnLettre($chiffre)
{

$centaine = 0;
$dizaine = 0;
$unite  = 0;
$reste  = 0;
$y  = 0;
$dix   = false;
$lettre  = "";
$reste   = $chiffre;

// print(" Valeur recue = $reste<br>");

for( $i = 1000000000; $i >= 1; $i = $i / 1000)
{
 $y = (int) ($reste / $i);
 print("$y   =   $reste   /   $i  ");

...
...


When i call this function many time with different number i got strange
values for the $y var.

Sometime when i call the function with $chiffre = 5,  I got  got $y = 5 ,
and other time i got $y = 4 !!!! I also got the same strange comportment
when I call the function with $chiffre = 45, sometime i got $y = 45 and
dometime i got $y = 44 ...

This problem only occur when $i = 1. So in this case, for PHP,  5 / 1 = 4
!!!

if i replace  $y  = (int)($reste / $i); by  $y  = ($reste / $i); evrything
is ok, so it appear that it's the casting that is transforming the 5 value
in the 4 value.

If anybody has an explication,

Best regards,

Alain Deseine.

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

Reply via email to