awk value in floating point value -- want in dollars/cents
howdy folks,
I wrote a long bash script that logs into the database and runs a number of SQL queries then sends the data into a few reports. I've got it *just* about right and have a small problem. To calculate a "total" dollar number from US@US, THEM1@US and THEM2@US transactions I run this little command (note that the variables are all data gathered from queries & I'd rather not do the query over again -- just piece it together from the three variables): dollars_total=`echo $dollars_amount1 $dollars_amount2 $dollars_amount3 | awk '{totaldollars=($1 + $2 + $3)} END {print totaldollars}'` The command actually works but the output for one value came out like this: Tot$: 2.67824e+06 I'd really rather the data be formatted in a normal dollars & cents fashion. Does someone know how I can set a specific format on the data so that after the three fields are added together with awk that the data comes out in $ddddddd.cc format? Any help appreciated. Thanks. ß |
http://www.gnu.org/software/gawk/manual/gawk.html
well, this page is useful. I'll change the "print" to "printf" & use format control letters. I used this one: ...{printf "%2.10e\n", totaldollars}... ...which gave this as output: Tot$: 2.6782389000e+06 Not quite what I wanted but I'll keep working on it. |
Quote:
Code:
{printf "%9.5f\n", totaldollars} |
I only slightly modified that value to "%9.2f/n" so my cents value stays two digits. Thanks for your input. :)
ß |
Quote:
|
All times are GMT -5. The time now is 07:00 AM. |