Operating System - HP-UX
1822144 Members
3502 Online
109640 Solutions
New Discussion юеВ

awk printf %d and the 32-bit limit

 
SOLVED
Go to solution
Daniel Spooner
Occasional Contributor

awk printf %d and the 32-bit limit

printf %d cannot display this number
2279793797

instead it displays

2147483647 2GB!

How can I get around this - I need to perform subtraction on it, so cannot use a string.
3 REPLIES 3
Tom Danzig
Honored Contributor

Re: awk printf %d and the 32-bit limit

2147483648 is the maximum signed integer you can use (2^32).

Try defining the number as an unsigned integer (%u) as long as it will always be positive or use a floating point number.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: awk printf %d and the 32-bit limit

This will probably get you fixed in awk and will work with signed values:

i = 4000000000
j = 12
printf("%.0f\n",i - j)
# for formated output
printf("%12.0f\n",i - j)

If it ain't broke, I can fix that.
Daniel Spooner
Occasional Contributor

Re: awk printf %d and the 32-bit limit

Thank you both for your responses. Using "%.0f" has done the trick!
Cheers
Dan