[Thamesvalley-pm] Leading 0s problem with large integers

Charlie Harvey charlie at newint.org
Tue Jan 6 05:23:39 PST 2009


Duncan Kendall wrote:
> Hello,
> 
> I have a bit of code that is trying to format a number as a 10 digit
> string with leading 0s inserted as necessary.
---------8<-------------
> Can anyone offer up a neat and simple solution?

Its not especially elegant, but:

$len = 10;
$string = '0' x ($len - length $num) . $num;

-- 
Charlie Harvey
IT Manager
New Internationalist

t: +44 (0)1865 811402
f: +44 (0)1865 793152
w: http://www.newint.org/

New Internationalist is an independent not-for-profit communications
cooperative. Our multi-award winning magazine, New Internationalist,
brings to life the people, the ideas and the action in the fight for
global justice.

New Internationalist Publications Ltd. is incorporated in England
under no.1005239. Registered Office:
New Internationalist, 55 Rectory Road, Oxford,  OX4 1BW, UK


More information about the Thamesvalley-pm mailing list