[resolved] unwanted formatting of numbers
Code:
<?
for ($z=1; $z<=100; $z++) {
$temp_time = (20050505113200 + $z);
echo $temp_time.'<br>';
}
?>
Hello everybody.
I'm trying to loop through, adding 1 to the variable $temp_time, however PHP is outputting this "2.00505051132E+013".
Instead I would like:
20050505113201
20050505113202
etc.
Any help is appreciated.
Re: unwanted formatting of numbers
It works fine for me, have a look here:
http://allfreesoftware.helphousehost...ing/Test_1.php
It maybe a setting in your .ini file that maybe doing this :)
Cheers,
Ryanj
Re: unwanted formatting of numbers
Strange, very strange. Thanks sciguyryan, I'll check that out.
Has anyone else encountered such a problem?
Re: unwanted formatting of numbers
Its not a problem. This is how PHP displays floating point numbers over a particular value. You need to use the sprintf() function to format the number appropriatly. E.g. to give the number as an interger:
PHP Code:
printf('%.0f', $number);
Re: unwanted formatting of numbers
Quote:
Originally Posted by visualAd
Its not a problem. This is how PHP displays floating point numbers over a particular value. You need to use the
sprintf() function to format the number appropriatly. E.g. to give the number as an interger:
PHP Code:
printf('%.0f', $number);
Then... How did the link I posted work correctly with exactly the same code? How very odd :S
Cheers,
RyanJ
Re: unwanted formatting of numbers
It is because the size of a float and integers are system dependant . I.e: solitario's system, the precision of a float may only be 8 digits, whereas on your system it might be 16.
There may be something in the PHP.ini file which controls numeric output, I'll have a look.
Re: unwanted formatting of numbers
Quote:
Originally Posted by visualAd
It is because the size of a float and integers are system dependant . I.e: solitario's system, the precision of a float may only be 8 digits, whereas on your system it might be 16.
There may be something in the PHP.ini file which controls numeric output, I'll have a look.
Ah, Ok.
Thanks for the information.
Cheers,
RyanJ
Re: unwanted formatting of numbers
Thanks visualAd. That did it! :)