Search Results

Search: Posts Made By: lawsongeek
11
2,334
Posted By MaroonedAlien
As in the Perl example, just use integer...
As in the Perl example, just use integer arithmetic and you'll be fine. Separate dollars from cents at the end of your script.
11
2,334
Posted By Corona688
If this is intended to be arbitrarily accurate,...
If this is intended to be arbitrarily accurate, you should use bc. awk uses floating point numbers and may lose a penny here and there.
11
2,334
Posted By cjcox
all the choices you mention will work. ...
all the choices you mention will work.


awk '
{
val=$0 + 0
sum=sum+val
}
END {
l=length(sum)
if (l > 2)
printf("$%s.%s\n",substr(sum,1,(l-2)),substr(sum,(l-1)))
else
...
11
2,334
Posted By MaroonedAlien
Yes, lots of ways to do this. One example in...
Yes, lots of ways to do this. One example in Perl (not using error checking to keep it simple):

open(IN, "<my_file.txt");
while($in = <IN>)
{
$sum += $in;
}
$sum =~ /(\d+?)(\d\d)$/;...
Showing results 1 to 4 of 4

 
All times are GMT -4. The time now is 06:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy