in reply to Displaying big numbers as decimal
%d tells Perl to convert it to a signed integer; 32-bit signed integers (which may have been the norm in 2001 when this was asked) can only count up to about 2e9, i.e. a 10-digit number, and I believe it will overflow to -1 as you saw. Even a 64-bit signed (%ld) would top out at 8e18, which is a 19-digit decimal number.
%f (as recommended by another reply) tells Perl to treat the number as floating-point, and hopefully a double-precision one. That has a 53-bit mantissa, which can handle up to about 8e15 (a 16-digit number).
%Lf would be a long double (which in C99 only means "at least double precision"); on x86 CPUs this is generally an 80-bit number, with a 63-bit mantissa, which can go up to 8e18 (same as a signed 64-bit integer).
|
|---|