|
|
|
|
|||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Problem in awk while adding large numbers
Hi,
I am facing a totalling error in awk while adding large numbers (when the total 15 digits). Please see below: host:/home/neil>cat test_awk.ksh #!/bin/ksh # test_awk.ksh # Test script to test out summing up large numbers using awk # TEST: Should result in 18 "9"s !!! awk 'BEGIN { total = 0; } { total += $1; } END{ printf( "%.0f\n", total ); }' << EF 000999999999999996 009000000000000000 090000000000000002 900000000000000000 000000000000000001 EF host:/home/neil>test_awk.ksh 1000000000000000000 As you can see from the above awk is going with 1e+18 instead of 18 "9"s. Can someone please help me correct the above awk program so that it prints the correct output? Note: As per my requirements, 18 times "9"s is the maximum total that can be generated. Thanx - Neil |
![]() |
| Viewing: Web Development Archives > FAQs > Unix/Linux > Problem in awk while adding large numbers |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|