in reply to number formatting

im doing this:

$result = sprintf('%015d', $integer)

which when printed to html is:

$result = sprintf('%015d', 9789673814172)

the answer i get however is 000001443791101 instead of 009789673814172. anyone know what wrong?

Replies are listed 'Best First'.
Re: Re: number formatting
by dga (Hermit) on Aug 08, 2001 at 22:57 UTC

    I would guess that you rolled your 32 bit int over many times. Playing around in bc I got 1443346588 by subtracting out powers of 2 to get lower than 2^32

    On a 32 bit box with 32 bit perl I get -00000000000001. If you have the perl with the really long ints you might try %015ld which should allow a longer int.

    On an Alpha box (64 bits native) the %015ld works as expected (009789673814172). Also you may try (with loss of precision for non simple assignments %015.0lf which works as one might expect on my 32 bit perl.

Re: Re: number formatting
by Hofmator (Curate) on Aug 08, 2001 at 19:39 UTC

    try result = sprintf('%015.f', 9789673814172);

    -- Hofmator