|
-
May 27th, 2005, 11:49 AM
#1
Thread Starter
Lively Member
[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.
Last edited by solitario; May 30th, 2005 at 05:02 PM.
-
May 28th, 2005, 06:50 AM
#2
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
-
May 28th, 2005, 12:57 PM
#3
Thread Starter
Lively Member
Re: unwanted formatting of numbers
Strange, very strange. Thanks sciguyryan, I'll check that out.
Has anyone else encountered such a problem?
-
May 28th, 2005, 02:47 PM
#4
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);
-
May 29th, 2005, 06:49 AM
#5
Re: unwanted formatting of numbers
 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
-
May 29th, 2005, 08:12 AM
#6
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.
-
May 29th, 2005, 09:20 AM
#7
Re: unwanted formatting of numbers
 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
-
May 30th, 2005, 05:01 PM
#8
Thread Starter
Lively Member
Re: unwanted formatting of numbers
Thanks visualAd. That did it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|