Strange comportment ...

This is a discussion on Strange comportment ... within the PHP General forums, part of the PHP Programming Forums category; Hi, I got a function that do a very strange calculation ... Here is the code fragment function ChiffreEnLettre($chiffre) { $centaine = ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-29-2003
alain@cabinfo.com
 
Posts: n/a
Default Strange comportment ...

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.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:50 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0