From owner-freebsd-questions@FreeBSD.ORG Mon Nov 12 13:28:31 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2CC4616A417 for ; Mon, 12 Nov 2007 13:28:31 +0000 (UTC) (envelope-from patrick_dkt@yahoo.com.hk) Received: from web54304.mail.re2.yahoo.com (web54304.mail.re2.yahoo.com [206.190.49.114]) by mx1.freebsd.org (Postfix) with SMTP id E6A9F13C4A5 for ; Mon, 12 Nov 2007 13:28:30 +0000 (UTC) (envelope-from patrick_dkt@yahoo.com.hk) Received: (qmail 51386 invoked by uid 60001); 12 Nov 2007 13:01:31 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com.hk; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=ZEHD5ITv+Go9NBl/eZuOS6uzS2pulmPmIP6RqUQnWy4GawNke+7D6LDr2xpV95HNqBLnMM/ijCMU0AaMGrFL4IxjpKaublPch4MXgS/ScW8ipQVza4KBTM/e4Gt3XuwFAS7p2tlU48gnRvY5qi+6ksGGSI5HU+WLeq3a2kWvqWQ=; X-YMail-OSG: n2EukDAVM1n8hjPmmZuu9TLL2hFACLYkmrFZqySq0x9yK4OV1e1VzRJa5I4.dzxUeWLrgljESdl8iY7IhDt6mbfEJs6eh5j4sslu2YzhQYesDT38EBnDZxZJSvpDRA-- Received: from [61.18.170.41] by web54304.mail.re2.yahoo.com via HTTP; Mon, 12 Nov 2007 05:01:31 PST Date: Mon, 12 Nov 2007 05:01:31 -0800 (PST) From: Patrick Dung To: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <766805.50147.qm@web54304.mail.re2.yahoo.com> Subject: question about floating point calcuation with shell script / bc X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Nov 2007 13:28:31 -0000 Hi I have a file with numbers in each line. Each number is a decimal number. My task is to add them up and get the final answer. I have searched with the search engine. I found bash cannot handle floating point calculation. I tried to use 'bc' and found if the final answer is < 1 (eg. 0.2) It display .2 instead of 0.2 (no leading zero). Any suggestion or other methods? I know ksh could do floating point calculation but I am now familiar with ksh. Regards Patrick __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com