Results 1 to 8 of 8

Thread: [resolved] unwanted formatting of numbers

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    121

    Resolved [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.

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    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
    My Blog.

    Ryan Jones.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    121

    Re: unwanted formatting of numbers

    Strange, very strange. Thanks sciguyryan, I'll check that out.
    Has anyone else encountered such a problem?

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    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
    My Blog.

    Ryan Jones.

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    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
    My Blog.

    Ryan Jones.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    121

    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
  •  



Click Here to Expand Forum to Full Width