Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: number formatting

by costas (Scribe)
on Aug 08, 2001 at 19:28 UTC ( [id://103089]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://103089]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-28 21:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found