Search Results

Search: Posts Made By: lawsongeek
11
1,541
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
1,541
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
1,541
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)$/;...
11
1,541
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
...
Showing results 1 to 4 of 4

 

Featured Tech Videos

All times are GMT -4. The time now is 09:02 AM.
Unix & Linux Forums Content Copyright 1993-2019. All Rights Reserved.
Privacy Policy